Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding WARs to Java's classpath

I have two wars, foo.war and bar.war. foo uses classes from bar. I'm trying to start foo, and add to Java's classpath bar.war, but java throws a ClassNotFoundException.

If I rename bar.war to bar.jar and edit its directory structure to look like a jar, it works.

Java's documentation on the -CP switch does not mention war files:

 -classpath <class search path of directories and zip/jar files>
               A ; separated list of directories, JAR archives,
               and ZIP archives to search for class files.
like image 791
ripper234 Avatar asked Jul 27 '09 07:07

ripper234


1 Answers

WAR files are meant to be whole web applications, not libraries. They contain libraries, but in themselves they're applications.

One web application shouldn't depend on another application. They may depend on the same libraries, but not on each other.

Basically extract out the common functionality, make it a library (as a jar file) and either include that jar file in both WAR files or add it to a common part of the classpath.

like image 199
Jon Skeet Avatar answered Nov 07 '22 07:11

Jon Skeet