Generating a Jar in Eclipse including external library

允我心安 提交于 2019-12-17 16:49:31

问题


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.


回答1:


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 ...




回答2:


You actually should use Ant or Maven for your task, I see no other option. Ant is already packed with eclipse, you only need to install a JDK, not only a JRE.

Ant is very easy to learn and you can find billions of examples in the internet. With ant you can do exactly what you want.

Maven is the more up-to-date way to build and package jars and do much more other stuff. Maven also is a good choice for you.




回答3:


I'll second a vote for Maven. Eclipse has a decent maven integration (m2eclipse). Then check out this answer for building the jar effectively using Maven2

Building a runnable jar with Maven 2



来源:https://stackoverflow.com/questions/7986063/generating-a-jar-in-eclipse-including-external-library

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