简体   繁体   English

包括库生成jar并在Intellij上使用java -jar执行

[英]Including libraries generating jar and executing with java -jar on Intellij

I've been trying to execute a jar file through command line but I'm still getting an exception that I'm missing a library even though it was properly added as it's shown here . 我一直在尝试通过命令行执行一个jar文件,但我仍然得到一个异常,即使它已经正确添加,因为它在这里显示,我错过了一个库。 The library that I'm trying to run my code with is the opencv's lib. 我正在尝试运行我的代码的库是opencv的lib。 I'm able to run my app from intellij and generate a jar artifact that I can see the jar grows in size when I add the opencv lib but when I try to run the app from the command line with "java -jar Test.jar" I get the message that I'm missing the opencv library. 我能够从intellij运行我的应用程序并生成一个jar工件,当我添加opencv lib但是当我尝试使用“java -jar Test.jar”从命令行运行应用程序时,我可以看到jar增大了“我收到消息说我错过了opencv库。

rinaldi@rinaldi-work:~/Projects/Test/out/artifacts/Test_jar$ java -jar Test.jar Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at HelloWorld.<clinit>(HelloWorld.java:14)
at Main.main(Main.java:4)

I've also tried to run the app adding the path to the opencv's library: 我还尝试运行应用程序添加opencv库的路径:

:~/Projects/Test/out/production/Test$ java -cp .:~/Sources/opencv-master/build/bin/opencv-310.jar Main

And another attempt because opencv needs not only it's jar but also the /opencv-master/build/lib/ directory: 另一个尝试是因为opencv不仅需要它的jar,还需要/ opencv-master / build / lib /目录:

:~/Projects/Test/src$ java -cp :/home/rinaldi/Sources/opencv-master/build/bin/opencv-310.jar:/home/rinaldi/Sources/opencv-master/build/lib/ Main

Below are the images from intellij's configuration. 以下是intellij配置的图像。

文物窗口

模块窗口

I had to add the library this way: 我不得不这样添加库:

java -jar -Djava.library.path=/home/rinaldi/Sources/opencv-master/build/lib test.jar

Hope this helps someone. 希望这有助于某人。

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

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