12

I have a Dynamic Web Project in Eclipse which has a dependency to another Java project in my workspace. When running the web project in the build-in Tomcat server, I've added the project dependency to the class path in the run configuration. I would like to create a WAR for deploying the web project on an external server. The dependency Java project is added to the Java Build path in Eclipse, but when I export an WAR-file the library is not included. The Java project is also selected in the Order and Export. How can I create a WAR with where my dependencies are included?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
dhrm
  • 14,335
  • 34
  • 117
  • 183
  • 1
    How do you build your application? Maven? Ant? ...? – dwalldorf Apr 10 '12 at 12:17
  • Currently in Eclipse but right-clicking the project and *Export -> WAR*. – dhrm Apr 10 '12 at 12:18
  • I would recommend you to use a appropriate tool to build your application. Maybe take a look at maven. Otherwise, the solution of Jigar Joshi will work as well. – dwalldorf Apr 10 '12 at 12:24
  • Can you provide me with an example on how to generate a WAR with my dependencies using Maven? – dhrm Apr 10 '12 at 12:39

3 Answers3

23

I am using Eclipse Helios Java EE. Right click on the project. On the properties window for that project select "Deployment Assembly" in the tree on the left hand side. Click add and on the window that appears select "Java Build Path Entries". Select all the libraries that you wish to be included in the .war file. Proceed to export the project as a .war file. You will find the libraries under /WEB-INF/lib.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Waliaula Makokha
  • 815
  • 1
  • 11
  • 21
9

Maven multimodule project is well suited here,

If you don't want to go for it then just the build the dependency into (.jar) add it to runtime dependency of web project(/WEB-INF/lib) and build up the WAR

jmj
  • 237,923
  • 42
  • 401
  • 438
5

You need to install Maven for Eclipse and convert your project to a Maven-project (Right-click project -> Configure -> Convert to Maven project).

As you have configured your project, you can run it as "Maven Build..." and specify install:install to build a war file which, by default, includes your libraries from Maven.

Maven has quite to much feautures to explain all that right now. Just take a look at the project site. It'll take you some time to understand and configure but when you understand it, it will save a lot of time for you :)

dwalldorf
  • 1,379
  • 3
  • 12
  • 21