How to package libraries into my jar using Ant

强颜欢笑 提交于 2019-12-08 13:11:35

问题


My application relies on two external libraries, I have both in jar format and have added them to my classpath, making it possible to run my application within NetBeans.

However, I would like to package my application in an easy to use jar file. When I tried the automatic method of jar creation provided by NetBeans (where it auto generates a jarfile in dist/) and ran it on another computer, I got lots of ClassNotFound (or similar) exceptions for classes that I could tell were supposed to be provided by my other libraries.

Is there a way I can include the other jarfiles I have into my own jar? I've never created an application which relies on other libraries before so this is a first for me.


回答1:


You can add a "Class-path" line to your jar's manifest. The drawback is that you have to hard code the paths to a file system (not jar) location in the manifest. If you put them all in the same directory or a consistent relative directory, it should be manageable.

See: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Alternately you can try something line One-JAR: http://one-jar.sourceforge.net/



来源:https://stackoverflow.com/questions/8334588/how-to-package-libraries-into-my-jar-using-ant

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