简体   繁体   English

使用外部库导出可运行的jar文件

[英]export runnable jar file using external libraries

I build application that using two external libraries the first library is opencv and the second one is swt I finished the application and it's working fine in Eclipse I change to jar file it doesn't work then I change the loaded function jar file from: 我构建了一个使用两个外部库的应用程序,第一个库是opencv,第二个库是swt我完成了该应用程序,并且在Eclipse中可以正常工作,我将其更改为jar文件,但无法正常工作,然后从以下位置更改了加载的函数jar文件:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

to

System.load("/Users/AbdallahRizk/Documents/opencv/opencv-2.4.11/build/lib/libopencv_java2411.dylib");

Note: I'm using mac operating system. 注意:我使用的是Mac操作系统。

and I export the jar file again and I use the command: 然后再次导出jar文件,并使用以下命令:

java -XstartOnFirstThread -jar here.jar

because I apply swt library. 因为我申请了swt库。 And the jar file work perfect in my laptop. 而且jar文件在我的笔记本电脑中工作完美。 But once I tried it in the operating system such as ubuntu and windows it doesn't work and I received the following error: 但是,一旦我在诸如ubuntu和Windows之类的操作系统中尝试了它,它就无法工作,并且我收到以下错误消息:

在此处输入图片说明

I know that in windows no need for -XstartOnFirstThread but I tried both but I still receiving the same error. 我知道在Windows中不需要-XstartOnFirstThread,但我尝试了两者,但仍然收到相同的错误。 I haven't try it yet in another mac operating system but I'm sure it won't work because the loaded opencv library won't be available so I'm trying to packed all the external libraries inside my jar file to work dependently in ubuntu and windows and mac os x. 我还没有在另一个Mac操作系统中尝试过它,但是我确定它不会起作用,因为已加载的opencv库将不可用,因此我试图将所有外部库打包到jar文件中以独立工作在Ubuntu和Windows和Mac OS X中。

Based on my research there is a way to do it using maven. 根据我的研究,有一种方法可以使用maven进行。 Right now I'm using normal eclipse project so any suggestion how to use eclipse to create maven project and export jar file with all the libraries packed inside? 现在我正在使用普通的eclipse项目,所以有什么建议如何使用eclipse创建maven项目并导出打包了所有库的jar文件?

the error output is because the application have been developed on eclipse and export on mac platform so it won't work because swt is depend on one platform so to solve the the problem I had to compile everything again and export the jar file using eclipse on windows to be ending with two jars files one for mac and another one for windows. 错误输出是因为该应用程序已在eclipse上开发并在mac平台上导出,因此由于swt依赖于一个平台而无法工作,因此要解决该问题,我不得不再次编译所有内容并在eclipse上导出jar文件Windows将以两个jar文件结尾,一个用于Mac,另一个用于Windows。

Second issue the opencv library I build in function to ask about the dll file for windows or dylib file for opencv so the library will be loaded using this command 第二个问题是我内置的opencv库,用于询问Windows的dll文件或opencv的dylib文件,因此将使用此命令加载该库

          System.load(dll_path);

which is dll_path is a string type will be given from the user as a chooser to choose the dll or the dylib file every time it's run dll_path是字符串类型,每次运行时都会由用户提供选择器以选择dll或dylib文件

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

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