• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading a servlet using jdk1.4 in Tomcat

 
Nitin Kumar
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic