I'm trying to code an application in Java that can be executed in a Windows CE operating system.
For this, I use Eclipse on my Windows PC and then transfer the .jar file into my "smaller" system that operates with Windows CE. The .jar file is then executed with the Mysaifu JVM (because we need a JVM to execute a Java program in Windows CE).
So I started with a simple application that will launch a window (with JFrame) and when I tried to execute it, I got an error message :
java.lang.UnsatisfiedLinkError: Native library 'wcepeer' not found (as
file 'wcepeer') in gnu.classpath.boot.library.path and
java.library.path
I've tried to verify if the file representing the native library (wcepeer.dll) is in the correct folder, and I could see that the file is there with another library files, for example wcesound.dll, wcesecurity.dll, etc. Normally these files are provided in Program Files/Mysaifu JVM/jre/bin when I installed the JVM on my Windows CE system.
I've also tried to verify the presence of the wcepeer library with System.loadLibrary() :
try {
System.loadLibrary("wcepeer"); } catch(UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e); }
The result was :
Native code library failed to load. java.lang.UnsatisfiedLinkError: Native library 'wcepeer' not found (as
file 'wcepeer') in gnu.classpath.boot.library.path and
java.library.path
However when I replaced "wcepeer" with "wcesound" for example, there was no error. So I suppose that there's a problem with the wcepeer.dll file, but I've no idea how to solve it. I searched everywhere on the net, there's only a forum about this but it doesn't help too much.
Thanks in advance for helping.
Kindly regards,
You can use dependency walker (http://www.dependencywalker.com/) to open your DLL (it works also on CE dlls, since they use the same format as Windows ones) and see what dependencies this DLL has.
It may be that other DLLs are required (if they are statically linked via export lib your DLL will fail to load anyway) or that the DLL requires some system DLLs or APIs that are not supported on your device.
Windows CE is a componentized OS so you may have a different set of APIs, depending on the components you included in the OS image.
Related
I am trying to build a small personal project with opencv. I included the path to the opencv jar file in visual studio using the java dependencies then referenced libraries but i get the linker error: Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java430 in java.library.path. I have no idea what else i could do
UnsatisfiedLinkError isn't about jar files.
It's about 'native' files. These are generally stored as a .jnilib file on mac, as a .DLL on windows, and as a .so file on on most unixen.
They cannot be in jar files.
Some libraries will put in some effort and ship a whole bevy of them (as each architecture and OS has a unique dll/jnilib/so file that is needed) inside the jar, will find the 'right' one for your arch/os combo, unpack it someplace, and try to load it live.
This is either not working, or this library isn't doing that. Presumably the opencv site contains a tutorial on how to get it running; as native files are required, it's a bit more involved than 'just download, add to classpath, and voila'. I suggest you follow it precisely.
If you do have something that seems suitable (probably called opencv_java430.dll or whatnot), start java with java -Djava.library.path=/directory/containing/that/file the.rest.of.your.java.args - that should help.
I'm trying to do some template matching with the Java binding of OpenCV 4.3.0 in Eclipse, but attempting to load the template image always results in this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_0(Ljava/lang/String;I)J
The line of code where this exception is thrown is this:
flowerTemplate = Imgcodecs.imread("/templates/flowerpot_white.png", Imgcodecs.IMREAD_COLOR);
I have tried a number of solutions suggested on similar questions on StackOverflow and elsewhere on the internet, including:
Pointing at the native library folder with the "Native library location" variable in the user library definition in Eclipse.
Adding the native library folder location to my PATH variable.
Adding the native library .dll location to my PATH variable.
Setting up the Eclipse run configuration to add the native library folder & .dll locations to the PATH and CLASSPATH variables.
Loading the library with the appropriate Java code, in each of the three ways I saw it suggested, in three different places which all run before the code that throws the exception.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.load(<path_to_the_dll>);
File opencvLibrary = new File(System.mapLibraryName(Core.NATIVE_LIBRARY_NAME));
System.load(opencvLibrary.getAbsolutePath());
Placing the .dll in question into my source folder and every subfolder. I am running it from within Eclipse, so this is also the program's working directory.
UnsatisfiedLinkError is a runtime exception that happens when running your Java program. So placing your file in the source folder will not work.
You need it to be available in a place that your program can find it.
See this article for example:
https://www.javaworld.com/article/2077520/java-tip-23--write-native-methods.html
In it they place the library in Linux's library path. In windows you'd similarly place it in the current directory (where you're running from) or in some shared location.
This article explains Window's dll search order: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order
You shouldn't need to explicitly call System.loadLibrary() yourself. That's the library's responsibility.
Your problem is that OpenCV is improperly installed on your machine or inaccessible from Eclipse.
For instructions on how to make in work in Eclipse see:
Add .dll to java.library.path in Eclipse/PyDev Jython project
After removing every load method and then adding them back one-by-one, I determined that the issue was most likely caused by Eclipse loading the native library folder twice.
Hello This is my code :
if (isWindows()) {
//System.setProperty("jna.library.path", getClass().getResource("/resources/win32-x86").getPath());//netbeans WinOs
System.setProperty("jna.library.path", System.getProperty("user.dir").toString()+File.separator+"Desktop");//compiler WinOs
} else if (isMac()) {
//System.setProperty("jna.library.path", getClass().getResource("/resources").getPath());//netbeans MacOs
System.setProperty("jna.library.path", System.getProperty("user.dir").toString()+File.separator+"Desktop");//compiler MacOs
} else {
System.out.println("Your OS is not support!!");
}
Why I have 2 PATH (don't understand because for add an image i have only one Path) by OS, one for use with IDE and another for use with .JAR ?
I just realized, that when I'm use windows and I run the project (from netbeans) the "Library" load and I get the information, but when I compile and I launch my .jar I get error :
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: %1 is not a valid Win32 application.
My Structure
It is correct?
On mac only work with this command : java -jar "/System/Volumes/Data/Users/hugoclo/NetBeansProjects/Prezauto/dist/Prezauto.jar"since Terminal. If click on jar i have message error : Not Found .....
Sorry about my English,
There can be two reasons for the "why". While Java is cross-platform, JNA (which relies on some native code) must necessarily behave differently on different operating systems. Particularly in the case of loading DLLs (Windows) or dynamic libraries (OSX), you don't want to mix and match. Because it might be possible to have a dll with the same name compiled for different operating systems, JNA's Getting Started page identifies standard locations for these libraries:
Make your target library available to your Java program. There are several ways to do this:
The preferred method is to set the jna.library.path system property to the path to your target library. This property is similar to java.library.path, but only applies to libraries loaded by JNA.
Change the appropriate library access environment variable before launching the VM. This is PATH on Windows, LD_LIBRARY_PATH on Linux, and DYLD_LIBRARY_PATH on OSX.
Make your native library available on your classpath, under the path {OS}-{ARCH}/{LIBRARY}, where {OS}-{ARCH} is JNA's canonical prefix for native libraries (e.g. win32-x86, linux-amd64, or darwin). If the resource is within a jar file it will be automatically extracted when loaded.
In your code, you appear to be trying to do the first option (setting the jna.library.path) to include the user's desktop. That's fine for testing, not good for production, and likely the reason your compiled jar can't find it. Furthermore, by setting this variable, you are overwriting any previous (default) location for it. If you want to go this route, you should copy the saved location and then append your own additional path to it.
However, for code you'll distribute to users, you don't want to have to rely on an absolute file path. It's far better to put the library in a standard relative path location: a resources path (src/main/resources if using Maven) that will be available on your (or any user's) classpath when executing. This seems to align with the commented-out Windows branch of your code, which will look in the win32-x86 subdirectory of your resources folder.
You may have told your IDE to add something to the classpath (so it works there) but if it's not in a standard location, it may fail in a jar.
I'm not sure why the macOS branch of your code does not put the resources in the darwin subdirectory but it probably should.
I have got the SDK for a particular project. I have installed this SDK on my computer and then I have made some modifications to the sample code provided by my client. And after that I created the runnable JAR for this code from Eclipse and it runs successfully from both CMD as well as by double clicking on it.
Now I want my Jar file to be executed on others PC but I receive an error : No MorphoSmartSDKJavaWrapper in java.library.path.
I was also getting the same error but then I set the environment variables from system for this but I wanted to remove this dependency of environment variables so I wrote the code in Main Class to setup Environment Variables in memory and now without setting up any environment variables in the system manually I am able to successfully open my Jar file on my PC.
Now I want to run this Jar file on other PC but it gives me an error of "error : No MorphoSmartSDKJavaWrapper in java.library.path. "
I am not understanding what I am missing out. Why I am not able to open this JAR file by double click on other PC.
Thank you.
it is your application/jar depends on other wrapper library probably a dll( probably installed under program files when you installed the SDK). You need to provide that library when you run this application in other machines. A short cut way is providing it via command line args
java -cp xxxx.jar -Djava.library.path=path/to/lib
https://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-use/
As pointed out by #kuhajeyan your jar is looking for the native library (probably some dll) in the paths set in the java.library.path system property. The native library is available in your system after installaion of the SDK and java.library.path is pointing to that location where it is available. For the other systems for which you are getting the error, either the native library is not available or the java.library.path is not pointing to the location where it is available.
Since your requirement is to run the jar on double click then I'd suggest you to use
public static void load(String filename)
api of System claas to load the library as the application starts.
For example if your library file name is foo.dll and is located at C:\Program Files\Java\jdk1.8.0_73\bin then your method will look like the following:
System.load("C:\\Program Files\\Java\\jdk1.8.0_73\\bin\\foo.dll")
I'm going crazzy with Eclipse. I writing simple test class which uses external jar. which uses native library .dll
When I Running from Eclipse, command Run.
Here my stack trace:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\YAZ\bin\yaz4j.dll: The specified procedure could not be found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at org.yaz4j.Connection.<clinit>(Connection.java:56)
at ru.Test.testConnection(Test.java:20)
at ru.Test.main(Test.java:15)
But when I run this code from console like this
java -cp "bin;C:\Program Files\YAZ\java\yaz4j.jar" ru.Test
Everything works perfect!
It's the same code. How is it works in console and not works in Eclipse?
here how I plugin this referenced jar to my project in Eclipse:
The messages you get when native methods fail to link are dreadful. I can think of several root causes that might give this message:
The DLL isn't loading some other dependent DLL when loaded from Eclipse. This is governed by the Windows PATH environment variable, which could be different when you're running in Eclipse.
It's a 32-bit DLL, and you're running with a 64-bit JVM under Eclipse, but 32-bit from the command line (or vice versa.)
I have been struggling with exactly the same problem for some days now trying to use the YAZ toolkit in my project. The thing was that native libraries get loaded correctly on various test computers, but not on my personal PC.
In short: the cause of the problem is that the JVM loads the incorrect libxml2.dll and libxslt.dll dependent libraries.
When I launch the JVM from the IDE, it starts looking in the following places for the native libraries:
(jdk_home_dir)\jre\bin. Somehow this step is skipped on all other test computers when loading dependent libraries (other than the main yaz4j.dll). This way the test computers don't load the wrong dll's.
(jdk_home_dir)\bin
if you set the -Djava.library.path parameter, it will look in that dir at this step
%SystemRoot%\system32
%SystemRoot%
The working directory set for the project, if any. This step is skipped on my personal PC, for unknown reasons, but works on all other test computers.
the %path%
I have figured out this by using Process Monitor. Note that steps 1 and 2 may be interchanged.
The YAZ toolkit main DLL named yaz4j.dll makes secondary calls to other dll's in the toolkit: libxml2.dll and libxslt.dll (among others).
My JVM finds them in the (jdk_home)\jre\bin directory. They seem to be bundled with Java and they are obviously different from the ones in the YAZ toolkit.
That means that procedures that are being called by yaz4j.dll could not be found in those dll's. This way the UnsatisfiedLinkException is thrown.
My JVM seems to be always searching firstly for native libraries in (jdk_home)\jre\bin regardless of the environment %path% variable or the -Djava.library.path switch.
Replacing the dll's in that dir may break some JVM native functionality so I wouldn't recommend that.
So the last step that needs to be done is to figure out how to make the JVM load the correct libxml2.dll and libxslt.dll libraries.
Recompiling yaz4.dll to make it point to renamed libxml2.dll and libxslt.dll might be a potential solution.
I had same problem, you need to have JDK not JRE build path library