NoClassDefFoundError error
I have these 3 Java projects:
ProjectA
ProjectAEAR
ProjectB
ProjectA has a class that instantiates a class of ProjectB ProjectA also has a main class that instantiates and tests that class on ProjectA.
If I run the main class everything works great and the expected results are processed.
Now, on ProjectA I have cr开发者_Python百科eated a web service that instantiated the previous ProjectB class, and when I publish the ProjectAEAR project and call the webservice I get the following error:
org.apache.axis2.jaxws.WebServiceExceptionLogger log A java.lang.NoClassDefFoundError throwable was caught.
I get this error on the line where the ProjectB class is being instantiated.
ProjectA Setup:
Java Build Path -> Projects: ProjectB
Java Build Path -> Libraries: All JARS needed by project B
ProjectAEAR Setup:
Java EE Module Dependencies -> ProjectA, ProjectB, JARS needed by projectB (In Lib Dir checkbox selected)
ProjectB Setup:
Java Build Path -> Projects: nothing
Java Build Path -> Libraries: All JARS needed by project B
Please advise me.
Thanks
Please check your classpath for your j2ee app server. I suspect you have an alternative or conflicting JAR from the app server taking priority over the classpath provided in your EAR. Basic steps - open your ProjectA and ProjectB, and review each of the JARs. Then compare that with what is provided by your app server.
Assuming you have control over the code you can add a try/finally block at the relevant line throwing exceptions and use this snippet in your module to display where the files are being loaded from: http://snippets.dzone.com/posts/show/3719
You might find starting your unit tests with the debug classloader options helpful in diagnosing exactly where the dependency is loaded. (use -verbose:class option).
I would've put this as a comment, but apparently I don't have enough reputation for that.
I can't give you a direct answer, but my suggestion is this: export your EAR project as EAR file from Eclipse (I'm assuming this is Eclipse based on your setup information). Then examine the resulting file and check what is actually built. Probably some file is not exported. Maybe you need to check some of the checkboxes under project properties -> Java Build Path -> Order and Export.
The system to properly set up Eclipse projects for building and exporting is unnecessary complicated, for example see how to properly setup WAR projects here (which is different from your EAR project, but maybe you actually don't need EAR?): Eclipse WTP deployment of build path dependencies
精彩评论