I want to try JNotify, the plugin library for watching file system changes, but cannot figure out how to configure it. The web page for JNotify says that "java.library.path should point to the location of the native libraries that comes with jnotify (dlls, so dylibs etc)". I am rather new to Mac OS X and don't really know how to do this. I'm using NetBeans and was hoping there was a simple way of adding it to the path in there. I tried it by simply adding the jar file to the Libraries node in the project, and importing it by "import net.contentobjects.jnotify.*;", but that didn't help. I'm getting this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnotify in java.library.path
It also seems I need to add native libraries (.so file for Mac I guess) into the same path.
So how do I do this?
java.library.path is a Java system variable, you have to set this particular one by using the -D switch when launching the program:
java -Djava.library.path=/path/to/dylibs your.MainClass
It should be possible to tell Netbeans to add some command line parameters when starting your program somewhere in your project's properties.
On OS X, the directory you want is wherever the .dylib files are, not the .so ones.
JNotify does NOT work on MAC OSX 10.6.8. As simple as that. :( On Linux works fine! File modified is not correctly reported no matter what you try.
Related
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 need to create a runnable jar in Windows with Eclipse and start it with Linux
I'm getting an unsatisfiedLinkError while loading OpenCv. I have edited the correct library path for a Linux computer in Eclipse and finally created a runnable jar. When I start the *.jar file in linux and get the following error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
opencv_java2411 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
at java.lang.Runtime.loadLibrary0(Runtime.java:900)
at java.lang.System.loadLibrary(System.java:1087)
Basically i have two question.
1. How can i get the loaded library path at runtime?
2. Is it possible that the chosen way is not the right way to handle the problem?
Thanks
One important this to keep in mind for loading linux libraries with System.loadLibrary, omit the lib prefix in the library name, for instance, if the library name is libxyz.so, your call would be:
System.loadLibrary("xyz");
Set the path of OpenCV in the variable LD_LIBRARY_PATH. You can do it in the shell where you run the "jar". Use export command.
when I ran my application I got the above error, i have libusb-1.0.dll file in C:/windows/System32/ folder. but even though my application didn't find the path for libusb-1.0.dll. I don't know about native library. Please any one help me about this.
where should I place this dll file?
If you have a 64bit OS you probably need to put it in SysWow64 folder instead (on the same level as System32). But it's probably better to just put it in the same directory as the executable.
The reason this may work is that System32 despite the name contains all the 64bit dll's and 32bit applications (that are run in comnpatibility mode) are redirected to use SysWoW64 instead (Of which mos of the dll's thunk the calls through the 64bit libraries in system32).
Try to put /org/usb4java/windows-x86/libusb-1.0.dll in your project directory
It works for me, I'm using eclipse and I put the dll in my project directory
src/org/usb4java/windows-x86/libusb-1.0.dll
I am using Jacob jar file in my java application.
This Jacob jar file comes with a .dll file. I have added Jacob jar file to my classpath. But when I execute my application a runtime error occurs as
"couldn't load jacob-1.15-M3-x86.dll file"
How can I load this .dll file?
Edited:=================================================================================
I had set the "path" environment varaible to the dir that contains my .dll file and loading that .dll file as follows
static {
System.loadLibrary("jacob-1.15-M3-x86.dll");
}
but the following error occured
java.lang.UnsatisfiedLinkError: no jacob-1.15-M3-x86.dll in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1734)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at TemplateClass.TemplateClass.<clinit>(TemplateClass.java:14)
The 'jacob-1.15-M3-x86.dll' needs to be in a place where your the operating system can find it. You have a few options here:
You can place the .dll file in the directory you started your application from. If you have a batch script to start your application, it would be that directory. If you are starting in some sort of application server, it would typically be the 'bin' directory.
You can place the .dll file somewhere in the %PATH% environment variable. I may be easier to just update your PATH environment variable to include the directory that contains your .dll file.
Another option is to place your .dll into the %SystemRoot%\system32 directory. Usually this is 'C:\Windows\system32'. This option is not usually recommended unless it is a shared library like the MSCVRT runtime.
One other possible issue you might have. If the .dll is compiled as 32-bit, then you must be running in the 32-bit Java runtime. Likewise, if it is a 64-bit .dll it needs to be run in a 64-bit JRE.
Ah, that's not a compilation error but a runtime error.
My guess would be that your DLL needs to be on the PATH. Not CLASSPATH, but PATH, because that's where Windows looks for DLLs. Try either extending your PATH to include the location of your DLL, or do what many other people do: Dump the DLL into \Winnt\System\System32 or whatever the system directory is called on your box. Wherever all the other DLLs are, in other words.
Update
The error message you post, thankfully, is pointing out the exact problem. You can solve it by putting the directory containing your DLL into java.library.path This Sun forum thread shows a nice example: http://forums.sun.com/thread.jspa?threadID=627890
Actually, that's a lot less clean than it should be; this seems to be one of the "shadier" areas in Java. The thread wanders around a lot, I do advise you to read all the way through to see some problems and solutions. I think you'll be able to succeed with a little trial and error.
Other options :
set the property java.library.path to the directory containing the dll. Example :
java -Djava.library.path="path/to/directory/containing/the/dll" -jar appli.jar
in the code, load the dll explicitly, with System.load.
You need to set LD_LIBRARY_PATH. This will give you all the right steps to follow.
When you use System.loadLibrary() don't include the .dll at the end.
Also, if you are not setting java.library.path to point to the folder containing the DLL then the DLL should be in the directory where you launch your Java application from.
I had the same problem.
I see that the question is not "answered", so maybe none of the options above worked.
One of my last hypothesis was that the Jacob.dll is missing its dependency.
What I did was to get depend and check if all the dependence, used by Jacob are loaded.
Of course this works for Windows.
Cheers!
Background
So I am attempting to load a jnilib (specifically JOGL) into Java on Mac OS X at runtime. I have been following along the relevant Stack Overflow questions:
Maven and the JOGL Library
Loading DLL in Java - Eclipse - JNI
How to make a jar file that include all jar files
The end goal for me is to package platform specific JOGL files into a JAR and unzip them into a temp directory and load them at start-up. I worked my problem back to simply attempting to load JOGL using hard-coded paths:
File f = new File("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl.jnilib");
System.load(f.toString());
f = new File ("/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/libjogl_awt.jnilib");
System.load(f.toString());
I get the following exception when attempting to use the JOGL API:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jogl in java.library.path
But when I specify java.library.path by adding the following JVM option:
-Djava.library.path="/var/folders/+n/+nfb8NHsHiSpEh6AHMCyvE+++TI/-Tmp-/"
Everything works fine.
Question
Is it possible use System.load (or some other variant) on Mac OS X as a replacement for -Djava.library.path that is invoked at runtime?
You don't have to provide the java.library.path at startup. You can programmatically set it with
System.setProperty("java.library.path", "/var/folder/bla/foo/bar/");
I don't know if System.load() will work somehow without this library path.
Jogl always tries to auto-load all dependent libraries.
To avoid this, there should be a NativeLibLoader class where you can call disableLoading() before you load the libraries yourself via the System.load()
System.load(...) takes libraryName as argument. It doesn't take path to library as argument.
JVM searches for a library with specified name in the list of paths specified in -Djava.library.path;
Here there is nothing specific to Mac OS X. It searches for libraries in the same way on all operating systems.