aspose file tools*
The moose likes Tomcat and the fly likes Unable to compile class for JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Unable to compile class for JSP" Watch "Unable to compile class for JSP" New topic
Author

Unable to compile class for JSP

Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
Can someone help me with this error? The only thing I can figure out from it is that Tomcat is having trouble compiling one of my JSPs. Not where or why.
Lewin Chan
Ranch Hand

Joined: Oct 10, 2001
Posts: 214
Easiest way is to check out the java source file it's generated... You'll probalby spot it almost immediately.
The generated java files live in the tomcat work directory.


I have no java certifications. This makes me a bad programmer. Ignore my post.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

usually a "compiler" error of "-1 in the jsp file: null" means that Tomcat is unhappy with CATALINA_HOME, JAVA_HOME or the JVM/JRE/JDK

Make sure there are no spaces in the *_HOME variables, and that you are using a JDK, not just JRE. If you're running Tomcat as a service on Windows, ensure that the service is being started with an appropriate VM.
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
Originally posted by Mike Curwen:
usually a "compiler" error of "-1 in the jsp file: null" means that Tomcat is unhappy with CATALINA_HOME, JAVA_HOME or the JVM/JRE/JDK

Make sure there are no spaces in the *_HOME variables, and that you are using a JDK, not just JRE. If you're running Tomcat as a service on Windows, ensure that the service is being started with an appropriate VM.

I made sure that my CATALINA_HOME and JAVA_HOME vars are pointing to the correct locations and they are: D:\ALM\Java\Apache_Group\Tomcat_4.1 and D:\ALM\Java\j2sdk1.4.2_01 respectively. My path contains the following Java-related paths (CRs for legibility):
D:\ALM\Java\Apache_Group\Tomcat_4.1\bin;
D:\ALM\Java\j2sdk1.4.2_01\bin;
D:\ALM\Java\j2sdk1.4.2_01\jre\bin;
D:\ALM\Java\j2sdk1.4.2_01\jre\bin\server;
D:\ALM\Java\j2sdk1.4.2_01\jre\bin\client;
I'm stuck. I'd appreciate any additional pointers.
[ November 24, 2003: Message edited by: Michael Brewer ]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hi Michael, try the following workaround:
* Add an entry to the CLASSPATH: D:\ALM\Java\j2sdk1.4.2_01\jre\lib
* Copy jsp-api.jar (or whatever you have for your Tomcat implementation) from $tomcat_dir\common\lib into D:\ALM\Java\j2sdk1.4.2_01\jre\lib\ext and add D:\ALM\Java\j2sdk1.4.2_01\jre\lib\ext to your CLASSPATH.
Sometimes, this works.
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
Originally posted by Vad Fogel:
Hi Michael, try the following workaround:
* Add an entry to the CLASSPATH: D:\ALM\Java\j2sdk1.4.2_01\jre\lib
* Copy jsp-api.jar (or whatever you have for your Tomcat implementation) from $tomcat_dir\common\lib into D:\ALM\Java\j2sdk1.4.2_01\jre\lib\ext and add D:\ALM\Java\j2sdk1.4.2_01\jre\lib\ext to your CLASSPATH.
Sometimes, this works.

I don't have jsp-api.jar in my implementation, but I do have jasper-common.jar and jasper-runtime.jar, so I copied those as you said, but I'm still getting the same error.
[ November 24, 2003: Message edited by: Michael Brewer ]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hmm, that doesn't feel like ClassNotFoundException or can't-resolve-symbol errors. Maybe, you have an error in your source code? Can you drop it here if it's not too large?
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
I just reinstalled Tomcat with examples this time and even the examples won't compile. It must be a problem with my J2SE environment. I'm using 1.4.2_01. I'm going to see what I can do there. Thanks for the help guys, I may be back with more questions, but hopefully I'll be back with the solution.
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
OK, after I got back from vacation and re-installed my environment I was able to get a root cause error to why the JSP can't be compiled. And it's puzzling me. I just moved this code from JRun to Tomcat and it worked under JRun.

Is throwing a NullPointerException when Tomcat tries to compile my JSP. This line is in a class that is called by my JSP. The odd thing is that when I run javac to compile the class, no NullPointerException is thrown. Connection.html#createStatement() doesn't say that this method will throw a NullPointerException.
If anyone has any ideas what I should, I'd greatly appreciate it.
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
I RETURN WITH THE SOLUTION!
I discovered the cause of my problems. Looking at the stdoutlog revealed a ClassNotFoundException when trying to load the MS SQL Server 2000 JDBC driver. After making sure the paths were in both the CLASSPATH environment variable and the setclasspath.bat file as well as uninstalling the SQL Server JDBC drivers and reinstalling them to a folder hierarchy that didn't have any spaces in it, I finally found this discussion which introduced me to the solution to my problem: move the three MS SQL JDBC JAR files into %TOMCAT_HOME%/common/lib/.
Unfortunately, that discussion doesn't say why this step is required. Can someone explain to me why I needed to put those three JAR files in /common/lib/ when they were already sepcified in the classpath?
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

It's because Tomcat doesn't use a system CLASSPATH to setting.

If you mean that you set it in the CLASSPATH settings used in the Tomcat startup script... then that won't really help either.

So because it's in system CLASSPATH, it will probably compile, but when your web-app actually wants to use it, it must be found somewhere in the Tomcat classloader heirarchy:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/class-loader-howto.html
Michael Brewer
Ranch Hand

Joined: Jun 27, 2002
Posts: 54
Now I just finished reading http://jakarta.apache.org/tomcat/tomcat-4.1-doc/printer/class-loader-howto.html and come back here and see someone posted a pointer to it. (why isn't reply notification working?)
The how-to does say "however, the standard Tomcat 4 startup scripts $CATALINA_HOME/bin/catalina.sh or %CATALINA_HOME%\bin\catalina.bat) totally ignore the contents of the CLASSPATH environment variable itself". I would think the use of the phrase "standard Tomcat 4 startup scripts" would mean that you could have Tomcat load everything from setclasspath.bat while the System classloader is loading which would seem to me to be the only purpose for the setclasspath.bat file.
However, now after reading it I see that I probably shouldn't be loading JDBC drivers with the System classloader and in fact shouldn't be loading them with the Common classloader as the linked discussion recommends. I should put the SQL Server JDBC JARs into the %CATALINA_HOME%/shared/lib/ folder instead.
[ January 14, 2004: Message edited by: Michael Brewer ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to compile class for JSP