cannot access javax.servlet.http.HttpServlet error

cannot access javax.servlet.http.HttpServlet error

i am deploying a servlet in Weblogic and when i am setting the classpath of jdk1.4 i am getting an error in compilation

MyServlet1.java:5: cannot access javax.servlet.http.HttpServlet
bad class file: C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar(javax/servlet/http/HttpServlet.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

and when i am doing the compilation with the command

javac -source 1.4 -d WEB-INF\classes MyServlet1.java

its working absulutely fine
I think that because you are using the different version of JDK for compiling and for running your application server. Make sure that is you are using JDK 1.4 for your application server you also compile your servlet classes using JDK 1.4, or the other way around update your application server to use the later JDK.

 I Wayan Saryada i hav compiled my program through jdk 1.4 and i am using the weblogic 8.1 which supports only the classfiles compiled with jdk 1.4 so i use -source 1.4 but the servlet api is provided by the Apache foundation which is not compiled from jdk 1.5 not from jdk 1.4 so i am getting this error but now please tell me how to resolve this problem

I guess weblogic should have their own version of servlet API. So If you create a war file just don't include the servlet-api.jar with it so it can use the same version used by weblogic app server.

The class file version of 49.0 belongs to Java 1.5.x, whereas the one of 48.0 belongs to one of the Java 1.4.x version. The classfile structure had changed in 1.5 due to the introduction of several new features and changes made in the Java Language Specification.

From the error, one can deduce that a Java 1.4 classfile was expected, whereas a Java 1.5 classfile was found. It appears that the compiler is a Java 1.4 compiler, so you should attempt to verify whether you're using the right version of the Java compiler and also the right JDK (i.e. JDK home).

ADDENDUM

Ant tends to look for the javac executable in the $JAVA_HOME/bin/javac . If the JAVA_HOME environment variable has been set incorrectly, say to a Java 1.4 home, then there is a likelihood of getting the described error even in Eclipse.

ADDENDUM #2

The addition of entries to the PATH environment variable could result in altering the search classpath behavior of Ant, possibly resulting in a different tools.jar being used for the purpose of compiling the sources. This might be due to the jvm.dll from the JRE 1.4.2 installation being used to run Eclipse (and hence Ant).

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright