简体   繁体   English

无法在其他计算机上运行Jar文件。 错误:java.library.path中没有文件

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

I have got the SDK for a particular project. 我有一个特定项目的SDK。 I have installed this SDK on my computer and then I have made some modifications to the sample code provided by my client. 我已经在计算机上安装了此SDK,然后对客户端提供的示例代码进行了一些修改。 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. 之后,我从Eclipse中为该代码创建了可运行的JAR,它可以从CMD以及通过双击成功运行。

Now I want my Jar file to be executed on others PC but I receive an error : No MorphoSmartSDKJavaWrapper in java.library.path. 现在,我希望在其他PC上执行我的Jar文件,但是我收到一个错误:java.library.path中没有MorphoSmartSDKJavaWrapper。

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. 我也遇到了同样的错误,但是我为此从系统设置了环境变量,但是我想删除对环境变量的依赖,因此我在Main Class中编写了代码以在内存中设置环境变量,而现在没有设置任何环境变量在系统中手动运行,我能够在PC上成功打开Jar文件。

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. " 现在,我想在其他PC上运行此Jar文件,但它给我一个错误:“ 错误:java.library.path中没有MorphoSmartSDKJavaWrapper。

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. 为什么我无法通过在其他PC上双击来打开此JAR文件。 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). 它是您的应用程序/ jar依赖于其他包装器库,可能是dll(安装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 一种快捷方式是通过命令行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/ https://examples.javacodegeeks.com/java-basics/java-library-path-what-is-it-and-how-to-to/

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. 正如@kuhajeyan指出的那样,您的jar正在java.library.path系统属性中设置的路径中寻找本机库(可能是一些dll)。 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. 安装SDK之后,本机库在您的系统中可用,并且java.library.path指向该库所在的位置。 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. 对于您遇到错误的其他系统,本机库不可用或java.library.path未指向可用的位置。

Since your requirement is to run the jar on double click then I'd suggest you to use 由于您的要求是双击运行jar,因此建议您使用

public static void load(String filename)

api of System claas to load the library as the application starts. System claas的api在应用程序启动时加载库。

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: 例如,如果您的库文件名为foo.dll,并且位于C:\\ Program Files \\ Java \\ jdk1.8.0_73 \\ bin,则您的方法将如下所示:

System.load("C:\\Program Files\\Java\\jdk1.8.0_73\\bin\\foo.dll")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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