9

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.
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • I have a similar problem to this--I have dozens of jars and dozens of config files that get dumped into a war and would like to be able to run a groovy script using that as my "Classpath" and have it all just work. There are always alternatives, but this would have been the most flexible way and would have saved me days of work possibly... Oh well, on to the next solution. +1 for the question anyway--saved me some time. – Bill K Aug 15 '12 at 22:46

2 Answers2

16

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

The structure of a war file is very different then a jar so it doesn't work. The Java class files are kept inside classes directory of the WAR whereas Jar directly have the Java class files. Why don't you add the folder where you have the Java class files of bar.war?

What are you trying to achieve?

Bhushan Bhangale
  • 10,921
  • 5
  • 43
  • 71