Ch3micaL Ch3micaL -3 years ago 106
Java Question

create a war file via command line in Eclipse Mars

I want to Export my Eclipse project as a .war file. I know that there are many similar questions asked, but using Maven or Ant isn't an option regarding the size of the project and the limited ressources we have. Also the libraries we use are changing alot, which would mean a lot of work with ant. I have been trying around with the jar command, but it does ignore the dependencies.

Is there an option to accomplish that with the jar command. Would it work having the jar command take the .classpath file of my project into account?

My other option would be to write my own Eclipse plugin. What I'm bearing in mind is to simply start Eclipse and trigger the export that way. Any thoughts on that?

Thanks in advance

Answer Source

I think there is an export menu option in Eclipse that will allow you to export a project as a jar, war etc. Just right click on the project and select export, then pick the options you want.

It would be better to invest the time to build it properly using maven (or some other build framework though). Creating a project build which is tied to a particular IDE is a bad idea for a number of reasons. The main reason being that you want your build to be environment agnostic. I.e. you can run it on any computer and it will produce the same results. Since each developer will have a slightly different setup, and IDEs change over time, if you create a build which is tied to a specific version of IDE and a specific environment, then you cannot guarantee the build will always work, or produce the same output.

Some other advantages of automating your build using a build framework are that it allows you to run it on a build server (such as Jenkins) in a Continuous Integration manner. That build can then be triggered automatically when you commit a change to the project source control (git etc).

Using a build framework like maven forces you to specify which versions of dependencies you require for the build, and then allows the build to resolve those dependencies from a consistent, reliable source, so that the war you produce will always contain the same correct things it needs to run (rather than whatever you have in your local class path). When another developer comes along and picks up the project at a later date, or you return to it yourself after a break, its easy to recreate the project from where it was left without worrying about getting the right IDE setup.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download