Packaging JAR file in WAR file

17,155

I would recommend using something that does automatic dependency management for you. If you already have ant in place for your build script, ivy is a great solution. If you don't have a build script in place, maven might be worth looking into.

Dependency management automatically pulls in transitive dependencies for dependencies (jars) that you use directly.

Share:
17,155
Justin Wong
Author by

Justin Wong

Updated on June 26, 2022

Comments

  • Justin Wong
    Justin Wong almost 2 years

    I have a series of dependent Java projects. I'd like to package them together into a single JAR file to be used in my WAR file. These projects depend on a large number of external libraries and projects such as log4j, apache-commons etc.

    I select all the projects in Eclipse and export as a JAR file, then copy the JAR file into my /WEB-INF/lib folder of my WAR, then deploy my application. I have the following problems:

    1. ClassNotFoundException. The web application cannot find the libraries packaged into my JAR file. I solved this problem by moving out all the dependent libraries into the /WEB-INF/lib folder and adding class-path entries into the MANIFEST.MF of the JAR, a thoroughly painful process.

    2. The classes in the JAR file cannot find property files packaged inside the JAR. How do I solve this problem?

    Is there a standard solution for these problems? Thanks.