Community
Participate
Working Groups
Build Identifier: I20090611-1540 When I have a dynamic web project I have 2 other java projects in this web application's "Java Build Path", but when I publish the web application to the server and open the browser to invoke my servlet, runtime exception: NoClassDefFoundError is raised. The class is located in the Java project which has already been added in the Java build path. Reproducible: Always Steps to Reproduce: 1. Create a Java Project "MyJavaApp" and create a Class "A" with static method : hello() 2. Create a dynamic web project "MyWebApp" and write a simple servlet "HelloServlet.java" 3. Add Java project "MyJavaApp" into "MyWebApp" Java build path (Go to project tab, then add "MyJavaApp") 4. In "HelloServlet.java" call A.hello(). No compilation error. All good. 5. Add a new server for "MyWebApp", choose Tomcat 6 for example. 6. Publish "MyWebApp" to Tomcat server in eclipse by clicking on debug button in "Servers" tab. 7. Invoke "HelloServlet" in the browser to make it call "A.hello()" 8. You find exception: java.lang.NoClassDefFoundError: com/test/A As you can see that I have already included Java project " MyJavaApp" in " MyWebApp" build path and that's why step #4 does not complain anything. However, how after I deploy " MyWebApp" into the server then it start complaining "NoClassDefFoundError"? I guess the "publish" function for eclipse is failed to pick up those java classes in the dependency project(s).
Moving to WTP
zzhang, First, this sounds like you are using the JDT's Java Build Path to specify this compile dependency. You should be using the J2EE Module Dependencies, which not only adds it to the build path, but also tells WTP that the module should be published. However, even if you did not do this, you should have a warning that states that the module is on the Java Build path, but will not be published. On that warning, there is a quick fix that should also fix this issue up. As such, I am closing this, since if I do either of these two, it works for me.