I installed Apache Tomcat 7.0.28 in my JBuilder6. I use JDK 1.6.0_32 (jre6). I can get http://localhost:8080/ page. However, when I tried to run my JSP file, I encountered following error:

FileUpload.jsp: java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
FileUpload.jsp: Caused by java.lang.NoClassDefFoundError: org.apache.tools.ant.Task
...12 more
Could not find the main class: org.apache.jasper.jspC. Program will exit.

I tried google this error and was not able to find solution.

Dani AI

Generated

This error is happening because Tomcat’s JSP precompiler (JspC) is implemented as an Ant task and therefore needs Ant’s classes on the classpath. The class shown in your stack trace — org.apache.tools.ant.Task — is part of Apache Ant, and org.apache.jasper.JspC extends that Ant Task. See the Tomcat JspC API for the class hierarchy. (Tomcat docs show JspC inheriting from Ant’s Task.) Tomcat JspC API

Practical fixes

  • If you are not intentionally precompiling JSPs, run the JSP inside Tomcat (deploy the WAR / place the JSP under webapps) and let the container compile it at runtime. IDEs sometimes try to invoke org.apache.jasper.JspC for “build” or “preview” actions — change the run configuration so Tomcat handles JSPs instead of calling jspc directly.
  • If you are using Ant/JspC to precompile, make sure Ant’s jars (for example ant.jar) and the JDK’s tools.jar are on the classpath used to invoke JspC. The Ant manual and Tomcat examples show how the task needs tools.jar plus Tomcat jars in the task classpath. Ant jspc task docs

Quick checklist

  • Verify Tomcat is started with a JDK (JAVA_HOME points to a JDK), not just a JRE (jspc often needs tools.jar).
  • If you launch JspC directly, add Ant to the classpath (or run via an Ant build that has Ant on its classpath). Example invocation pattern:
    java -cp "$JAVA_HOME/lib/tools.jar:/path/to/ant/lib/ant.jar:/path/to/tomcat/lib/*" org.apache.jasper.JspC [options]
  • Avoid permanently dumping Ant jars into Tomcat/lib unless you understand the mixing/version risks; prefer fixing the build/run classpath in the IDE or Ant script.

— check whether JBuilder is trying to precompile JSPs. was on the right track: this is a library/classpath problem; adding the Ant/tooling jars to the classpath (or switching to container compilation) will resolve the NoClassDefFoundError.

Mybe Library problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.