Adding comm.jar into my jar

白昼怎懂夜的黑 提交于 2019-12-22 08:01:31

问题


I add comm.jar library into my .jar and I get javax.comm.NoSuchPortException.

Is this bug because I haven't add javax.comm.properties and win32com.dll into my jar? How can I add this file inside manifest?


回答1:


Java does not support Jars within Jars. The correct way to ensure the javax.comm packages are on the run-time class-path of the application is to add a manifest that provides a relative path to the dependent Jar, and ensure that Jar is in the right place to be found. For details see Working with Manifest Files: The Basics & particularly Adding Classes to the JAR File's Classpath in the Java Tutorial.

There are other methods that can be used for applets and apps. launched using Java Web Start.




回答2:


@Gogoo's answer says to copy stuff into your JVM installation directory.

It should work, but it is generally not a good idea:

  • The stuff that you install that way will be shared by all applications that you run using that installation. Depending on the what it is, it may interfere with other applications.

  • Each time you update your JVM, you have to remember to copy those files into the new installation directory.

IMO, a better idea is to put those files in a separate directory tree, and write a wrapper script to launch your application with the files on the classpath and library path. And/or see @Andrew Thompson's answer.




回答3:


Try FatJar.

The Fat Jar Eclipse Plug-In is a Deployment-Tool which deploys an Eclipse java-project into one executable jar.

It adds the Entry "Build Fat-JAR" to the Export-Wizard. In addition to the eclipse standard jar-exporter referenced classes and jars are included to the "Fat-Jar", so the resulting jar contains all needed classes and can be executed directly with "java -jar", no classpath has to be set, no additional jars have to be deployed.




回答4:


copy comm.jar \jdk1.6\jre\lib\ext
copy win32com.dll \jdk1.6\bin
copy javax.comm.properties \jdk1.6\jre\lib

and start your.jar over command line:

java -jar your.jar



来源:https://stackoverflow.com/questions/7090427/adding-comm-jar-into-my-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!