This applet was run through javaws. The jnlp file allows me to download the base jar, as well as some native libraries, compacted in separate jars for each OS.
With java support ending for browsers, I wanted to allow the applet to run as a normal app on the client, but with a web server on top of it.
So far, I can call methods on the main/base jar. However, this jar calls System.loadLibrary to load such native libraries. However, I always get an UnsatisfiedLinkError.
The native library jars are dependencies of the project, and I've even tried extracting the dylib and dll files from the jars. I've set the java.library.path flag to the path where they're at.
Nonetheless, I still get java.lang.UnsatisfiedLinkError: no library in java.library.path: /Users/me/java/apps.
The web server I'm using is NanoHTTPD.
Can dependencies access local files? Do I need to give java permission to access the directory? Do I need to name the jars containing these native libraries accordingly?
I'm on MacOS (the lib files follow the naming convention "lib{{LIBRARY_NAME}}.dylib").
These third-party jars I’m using are signed
(base Java jar with Java classes and jars containing OS specific native libraries).
Related
I have created a spring application which uses google or-tools. For that, I am importing jniortools using System.loadLibrary("jniortools"). when I provide the .dll file and run the war file it runs perfectly. But when I provide the .so file path in lib, I get the unsatisfiedlinkerror.
Taken from here, a solution for using or-tools over Intellij:
To make it work using Intellij (over a windows machine) you need to:
Install Microsoft Visual C++ Redistributable for Visual Studio
Download and extract the OR-Tools library for Java
In intellij, add jar dependency to the 2 jars under the lib folder of the extracted files (each of the 2 jars separately, do not add to lib folder itself. This is why).
Add the lib library path to VM options. In Intellij edit your run-configuration and add to vm options: -Djava.library.path=<path to the lib folder that hold the jars>
Load the jni library statically by adding the below code to your class (as mentioned here.)
static {
System.loadLibrary("jniortools");
}
I am building an app on mac osx using javafx maven plugin. This plugin automatically creates the complete JRE inside the Java.runtime folder during the build process. But it doesnt contain the java.exe inside it.
I want to launch a jar within the app but for that I need java executable also inside the app. If I paste the java executable from system java bin folder inside the Java runtime folder of my app , I am able to launch my jar (problem gets resolved) but I am not able to launch this app to the mac app store because the Java executable is code signed with Developer ID Application: Oracle America, Inc. and has a bundle identifier of net.java.openjdk.cmd .This doesnt allow my app to be uploaded on itunes.
Is there any way out , where using javafx maven plugin I also get the java executable inside my app during the build process rahter than copying it from my system java inside my app which has a different code signature.
Instead of trying to implement system-dependent code in Java, it is better to use the facilities that are available in Java for executing a jar in the current JRE. It is possible to create a URLClassLoader https://docs.oracle.com/javase/7/docs/api/java/net/URLClassLoader.html which links to your jar (and any dependencies). From there you can use reflection to load your main class from that classloader, and execute it. There is no need to launch a new JRE (At a huge cost in RAM) unless you need to make actual changes to operating system state, such as executing SUID.
See related question if you need to execute jars with privileged operations: Signed applet loads signed jar-files using URLClassLoader with security issue
I was able to compile the native 0.6.0 libraries of JCuda on a Mac OSX 10.9.3 64-bit system (http://www.jcuda.org/downloads/downloads.html). Unfortunately Im not smart enough to package everything into a jar. Can someone help me to do so? I created a Netbeans project and copied the contents of all provided Java src folders into it. Then I packaged everything into a jar. Using Jarsplice 0.4.0 I then tried to build a Jar file containing all the native library files listed below (except the first .a file). Unfortunately when I linked the resulting jar into my project and run it, it wasnt working since a libJCudaRuntime-apple-x86_64.jnilib was missing.
Thank you in advance
Radek
My lib folder contains:
libCommonJNI.a
libJCublas-apple-x86_64.dylib
libJCublas2-apple-x86_64.dylib
libJCudaDriver-apple-x86_64.dylib
libJCudaRuntime-apple-x86_64.dylib
libJCufft-apple-x86_64.dylib
libJCurand-apple-x86_64.dylib
libJCusparse-apple-x86_64.dylib
Just to have this answered here as well: The native libraries can not be packed directly into a JAR (or rather: They can currently not be loaded if they are only contained in the JAR).
Although the infrastructure of the JCuda LibUtils class basically offers the possibility to do this, it is not "officially" supported. One reason for that is that this would only make sense when all native libraries for all operating systems were available (in 32 and 64 bit). Then it would be possible to put all these libraries into a JAR, and unpack and load them transparently at runtime.
It usually takes a while until all native libraries are available. The problem may be alleviated with things like https://github.com/MysterionRise/mavenized-jcuda , which manages the dependencies to the native libraries.
I'm working on a game that uses LWJGL and thus requires native libraries specific to each platform. On this page, the author shows how to use the <nativelib> tag with Java Webstart to include JARs containing the appropriate native libraries. I'm trying to do something similar, but without using Webstart.
I tried adding the native library JARs to my main executable JAR's classpath, but that didn't work. Currently, the native libraries just sit in the same directory as the main JAR and that works fine, but I'd like to make it a bit tidier.
You have to use the JVM argument -Djava.library.path=/path/to/libs
Generate your jar, then add a script containing something like the following:
#!/bin/bash
java -Djava.libraray.path=. -jar your.jar
Asserting that the native libs are placed in the same folder as your application jar file.
I am just starting to learn JNI. I have been following a simple example, and I have created a Java app that calls a Hello World method in a native library. I'd like to target Win32 and Linux x86.
My library resides in a DLL, and I can call it just fine using LoadLibrary when the DLL is added to the root of my Eclipse project.
However, I can't figure out how to get Eclipse to export a runnable JAR that includes the DLL and the .SO file for Linux.
So my question is basically; how would you go about creating a project in Eclipse and include several versions of the same native library?
Thank you,
Martin
For runnable JARs, what you need to do is extract to the temporary directory (maybe in a static { } block) and then load the DLL from that directory (using System.loadLibrary() in the same block). To do this, you need to subclass ClassLoader and override the findLibrary() method to allow libraries to be found in that directory. You can do whatever logic you need to here to load the particular platform libraries. To be honest, the naming for the libraries on the different platforms should be similar anyway -- I believe that you omit the 'lib' part when loading, and the extension. That's the gist of it. Probably easier to use One-JAR as the other poster mentioned :)
You might want to check out the One-JAR project. It lets you package your application and its dependencies (including native libraries) to a single jar file.