File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Loading a servlet using jdk1.4 in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Loading a servlet using jdk1.4 in Tomcat" Watch "Loading a servlet using jdk1.4 in Tomcat" New topic
Author

Loading a servlet using jdk1.4 in Tomcat

Nitin Kumar
Greenhorn

Joined: Apr 18, 2005
Posts: 29
Hi ,
I am new to servlets and I am trying to run my first servlet using standalone Toncat Server, but I am getting some errors.

I followed these steps

1 Downloaded tomcat_5.5.9.zip and '5.5.9 Compat.jar' from Apache site.
2 Unpacked them in a local directory(D:\Tomcat) . While unpacking '5.5.9 Compat.jar' I replaced some of the jar that were in original folder.
3 I pointed JAVA_HOME to jdk1.4.2_06. This I did using environment variables.
4 Changed the port in D:\Tomcat\jakarta-tomcat-5.5.9\conf\server.xml to 80
5 Modified D:\Tomcat\jakarta-tomcat-5.5.9\conf\web.xml
Uncommented the Servlet-Name and Servlet-Invoker
6 Complided a small java class (HelloWorld.java) and put the class file into
D:\Tomcat\jakarta-tomcat-5.5.9\webapps\ROOT\WEB-INF\classes

7 Tried to access the class file using the URL http://localhost/servlet/HelloWorld
But I am getting following error

javax.servlet.ServletException: Cannot allocate servlet instance for path /servlet/HelloServlet
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:388)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.UnsupportedClassVersionError: HelloServlet (Unsupported major.minor version 49.0)
java.lang.ClassLoader.defineClass0(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:539)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1629)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:850)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1299)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1181)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:369)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

But when I set JAVA_HOME to jdk1.5 , it works fine. Whats wrong here ?
As I have downloaded 5.5.9 Compat.jar and unpacked it, it should work with JDK1.4 also?
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
your servlet (and/or classes it uses) were compiled using a 1.5 compiler. When you try to run them on a 1.4 JVM that's the error you get.

1.4 compilers produce classfiles with an internal version number 48, 1.5 compilers create classfiles with version 49.


42
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
The quick solution is to use the compiler option -source 1.4
to produce compatible code.
See the tooldocs for javac for more details
Bill
[ April 25, 2005: Message edited by: William Brogden ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a servlet using jdk1.4 in Tomcat
 
Similar Threads
Hi Servlet invoke error
Problem compiling servlet [RESOLVED]
UnsatisfiedLinkError
Error 500 when compiling servlet
I'm not sure the problem is the servlet