I am trying to add and use a program called JVLC to my program. I downloaded a zip file that contains a jar file(jvlc.jar) for java interface and 2 dll files (jvlc.dll , libvlc.dll) and a folder that contains many dll files. when I run my program an UnsatisfiedLinkError occurs.
I used this code to add those 2 dll files to my project.
System.loadLibrary("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\jvlc.dll");
System.loadLibrary("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\libvlc.dll");
but still there is error:
UnsatisfiedLinkError: Directory
separator should not appear in library
name
Is it necessary to add all folder to library paths? If yes how?
please guide me.
The System.loadLibrary method loads a libary based on a library name (libName, without extension) and not through file name. Example, Java comes with a zip.dll / zip.so (Linux) that is used when we use the Zip Deflater/Inflater classes for zip files.
If you want to use specify a dll file name, use the System.load(String filename) method otherwise, register your DLL in a java lib path.
An example can be found here.
For your example, please do this:
//Your code....
System.loadLibrary("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\jvlc.dll");
System.loadLibrary("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\libvlc.dll");
//Replace with this...
System.load("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\jvlc.dll");
System.load("C:\\Users\\sajad\\Documents\\Downloads\\Compressed\\JVLC\\libvlc.dll");
According to this tutorial:
You need to set LD_LIBRARY_PATH (on Linux/Unix) or PATH (Windows) include the directory where the libraries are.
You don't need the .dll suffix.
Related
I currently wrote a simple GUI in Eclipse which runs as intended. I was hoping to export it so I can share it with my friend (who doesn't need to install eclipse and the java libraries). I tried all 3 library handling method Eclipse provides and none of them works. I read a little online and saw something about a manifest file, but wasn't quite sure what to do with it. Is it going to help?
This is where I placed the folder that comes with the .dll file.
This is the result. Am I doing something wrong?
As indicated by the error messages in the first screenshot, what you are missing here is the native library - the software library written and compiled to native code specific to the operating system. What you will need to do is provide the libraries specific to the operating system on which your software will run, eg. dlls for 32 or 64 bit Windows. The manifest does not provide the capability to include those libraries.
When the program is run on Windows, Java will look for native libraries in the following locations:
The current directory
The directories in the PATH environment variable
The directories in java.library.path (if it's specified)
It may be easiest to simply put all files in the one directory. If you do this, you should be able to run the program in the same way as you do now.
The java.library.path option is only needed if you want to put your native library files in a directory separate to the one in which you run your program and not on your PATH. It is only in this case that you will need to add java.library.path, eg. by adding -Djava.library.path=c:\path\to\your\lib after java. Also note that you may use a relative path, ie. a path that is relative to the directory you are in when you execute the command.
I also see from your later error messages that you have another dependency, but on a java library LeapJava.jar. As running a jar with -jar will only work if you have a single jar, but because you have more than one (your own program plus the dependency), you'll instead need to use the -classpath (or -cp for short) argument and add your main class. The classpath argument is a semicolon-separated list of classpath locations, while the main class is the one containing your public static void main method, eg. your.package.name.YourMainClass. So assuming your UI.jar is still in C:\Users\Ian\Desktop\Leap Data UI, you should be able to navigate to that directory and execute with:
java -cp UI.jar;UI_lib\LeapJava.jar -Djava.library.path="UI_lib\x64" your.package.name.YourMainClass
I'm currently working on a java library (binding) which uses some own written native code. This native code is compiled as a .so file for multiple architectures (arm-v7, i686, x86-64, etc).
I know in android you have to create a folder called jniLibs with subfolders for each architecture containing the proper .so file. Then with an Android.mk file and System.loadLibrary I can include these files into my code.
However, I have no clue how to include these .so files in a normal java project/library. I have read online that System.loadLibrary only works for looking through normal files (and not necessarily project files).
You can't have anything other than code in an android .jar file, however, you can have resources in an .aar file.
Android Archive Library (aar) vs standard jar
You will find that the .aar for your library is the redistributable/reusable compiled version of your library.
You can do it as how SWT did it -- extract the library files from your .jar file to user's home directory (so you are sure you have access to write in it) manually by java code.
You can check the source code of org.eclipse.swt.internal.Library, method extract().
I'm a little confused by this error. I'm new to Java and the error seems pretty self explanatory, but I've checked my paths (even defined my own) and it still fails to find this library. Is there something I'm doing wrong? See directory screenshot and error screenshot below:
UPDATE
UPDATE 2
If I create a new NetBeans project this works fine. Same code and everything. If I create new IntelliJ project I get this error above. I must be missing something in IntelliJ
UPDATE 3
Found the solution. Adding dependencies is a bit different in IntelliJ. Thanks all for the help.
http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html
Obidisc4j is a .jar file. You just dont see its extension in the explorer.
Regular jar files are not loaded by System.loadLibrary. They are automatically loaded by the JVM's classLoader.
You are using a native library. It doen't matter if that library is in the classpath. There are 4 ways you can make the Java runtime load your shared library at runtime:
Call System.load to load the .so from an explicitly specified absolute path.
Copy the shared library to one of the paths already listed in java.library.path
Modify the LD_LIBRARY_PATH environment variable to include the directory where the shared library is located.
Specify the java.library.path on the command line by using the -D option.
Seems like your application is trying to find out a obidisc4j.dll (for Windows) or obidisc4j.so (for Linux). The file must be present on the PATH (but not the classpath). If you are not sure what PATH is your Java application searching in, you can write the following statement, before the point where the exception takes place, to find out the PATH.
System.out.println(System.getProperty("java.library.path"));
This will tell you about the paths where your DLL or SO file should be placed. You just need to place the file in ONE of those N-paths.
I'm having a difficult time figuring this one out. I have an eclipse project where I created a user library which includes the jar file opencv_java245.jar.
I've tried everything I can think of, adding the jar to the path, adding the directory of the jar to the path variable.
I checked my java versions, I've tried VM arguments in run config.
I still get the same UnsatisfiedLinkError on this line System.loadLibrary("opencv_java245");
Right now I have a user library with opencv-245.jar located in C:\OpenCV\opencv\build\java
The Native Library Location for it is located in C:/OpenCV/opencv/build/java
My PATH variable also has that same location added to it.
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
this the code for detect default dll file..
Actually for future reference for anyone I found the solution. Inside the java folder for OpenCV there is a x64 and x86 folder containing dll files for OpenCV. Copy over either 64 bit or 32 bit dll file to your java folder for OpenCV and it should work.
I have an external library with dll files, I'm using netbeans and java. I would like to add a library path like: "java -Djava.library.path="bin"", to my jar file, how can i do this?
I have to add the relative path, and i do have to add it, becouse it will be a program for users and I want it to not require install at all.
Thanks
You can use an absolute path for your DLLs. You don't need to change the path if you know where the library should be loaded from.
System.load("C:/my/path/to/dll/my.dll");
You need to specify the full JAR path:
java -Djava.library.path="bin/my.jar"