Reputation: 457
I have a Java EE Web project deployed and running fine (project1)..
I create another project (project2) and add project1 in Web Deployment Assembly..
I am able to access all classes defined in project1 and no compile time error..
While running the project, it gives runtime error like NoClassDefFoundError for classes in project1..
Am I doing anything wrong?
Upvotes: 0
Views: 57
Reputation: 1840
Looks like the project1 is absent from project2 classpath. Try to compile project1 to a jar (I assume it's a .war now) and put the jar on the classpath.
War
files are not library files as jars
are. They have the specific purpose of packaging a webapp in one distributable file. Your IDE is apparently smart enough to reach into the war, but that's not a rule.
IMO the best you can do is to create another project where you put all the shared classes and package it as a jar (say, project3.jar
). Then, put project3
as a dependency of both project1
and project2
and you'll have a clean, legible structure that works.
Upvotes: 1