简体   繁体   中英

Unable to run Jar file on other computer. Error: no file in java.library.path

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM