且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Eclipse中生成包含外部库的jar

更新时间:2023-09-30 12:45:40

Eclipse有自己的Jar导出向导,用于生成包含所需库的可运行jar或将文件夹中所需的库放在jar旁边。



进入文件--->导出,然后选择Java - Runnable Jar





然后,您可以选择如何打包和如何处理库:





你也可以保存蚂蚁脚本供以后修改或使用...


I have a java application I've written in eclipse. It works fine there.

It works fine run from a command line in the directory where I export it to. In that directory is another directory containing two jar files that I need for the application, and the manifest file has a Class-path option specifying them.

I want a way to use eclipse to generate the necessary file(s) to package this application to run on another machine. Is that possible?

If I choose "create executable jar file", it creates this huge file; it does unpack and repack the two libraries, which I know is one way to get their functionality included. I would actually prefer it if they were left as their own jars somehow, but I am not certain eclipse can do that. More annoying is the fact that the executable jar file option puts lots of files from my eclipse project into that jar file. I don't see an option to choose what gets included there, though I do see a place to enter inclusion and exclusion "rules' in the project properties. Do those apply here? Is there somewhere else I go to select what does and does not get included in the "executable jar"?

If I choose "create jar" (ins of "create executable jar"), I don't see where there's an option to include these two jar files anywhere. Perhaps there is no place to include them where they could be used.

If possible, I do not want to use Ant, I do not want to use Maven, I do not want to download another tool. It seems to me that Eclipse already has all this information and I suspect it can already do this without having to go and learn yet another "nifty" tool.

Eclipse has its own Jar export wizard for generate a runnable jar packed with required library or with the required library in a folder aside the jar.

Going in File ---> Export then choose Java - Runnable Jar

You can then choose how pack the jar and how handling libraries :

You can also save the ant script for later modification or use ...