• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems compiling servlet

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I tried compilng my servlet file I get the following error.

C:\Documents and Settings\MyServlet>javac -d WEB-INF\classes src
\mypackage\*.java
src\mypackage\LoginServlet.java:21: cannot access javax.servlet.http.HttpServlet

bad class file: C:\Documents and Settings\My Documents\Downloads\servl
et-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 classpa
th.
public class LoginServlet extends HttpServlet {

Can any one please help me out.

Thanks in advance
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the first problem is that the servlet-api.jar is not in the class path just set it in class path and then tell whats message you are getting...may be that resolves the problem
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting the same error again.

Even JBoss is not working. I am getting the exception as

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jboss/Mai
n (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have compiled the class with a Java version later than the Java version you're trying to run it with.
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I couldn't understand you clearly.

I have set CLASSPATH to C:\Documents and Settings\My Documents\Downloads\servlet-api.jar

My JAVA_HOME is set to C:\Program Files\j2sdk1.4.2_02

My Path is set to C:\Program Files\j2sdk1.4.2_02\bin;C:\Program Files\Java\jre1.6.0_04\bin;

If I have gone wrong somewhere do say and Can you advise me what to do for this?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're running the class with an earlier version than you're compiling with.

In other words, you're compiling with 1.6 and trying to run with 1.4 (or 1.5). Either run the class with a later version of Java, or compile with an earlier version.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

My JAVA_HOME is set to C:\Program Files\j2sdk1.4.2_02

My Path is set to C:\Program Files\j2sdk1.4.2_02\bin;C:\Program Files\Java\jre1.6.0_04\bin;


Both these indicate that you're using Java 1.4, which you should run, not walk, to delete from your system - that's how obsolete it is.

To make matters worse, you have the binaries of both Java 1.4 and Java 6 in the PATH - that's a problem waiting to happen.
 
adil qureshi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

jagan raja wrote:I am getting the same error again.

Even JBoss is not working. I am getting the exception as

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jboss/Mai
n (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
3)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)



hey just ensure that you are using the same version of java everywhere .
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I my CLASSPATH is set to

C:\Documents and Settings\My Documents\Downloads\servlet-api.jar



PATH

C:\Program Files\Java\jre1.6.0_04\bin



JAVA_HOME

C:\Program Files\Java\jre1.6.0_04



After doing this my JBOSS runs fine.

But when i try compile my servlet file I get the same error as before.

C:\Documents and Settings\jagan\MyServlet>javac -d WEB-INF\classes src
\mypackage\*.java
src\mypackage\LoginServlet.java:12: cannot access javax.servlet.http.HttpServlet

bad class file: C:\Documents and Settings\604848923\My Documents\Downloads\servl
et-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 classpa
th.
public class LoginServlet extends HttpServlet {
^
1 error


Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The number "48.0" indicates that you're still using Java 1.4. My guess is that you won't be making much progress until you've completely erased that from your system.

See byte offsets 6 and 7 in http://en.wikipedia.org/wiki/Class_%28file_format%29#General_layout for what that number means.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're sure you're getting the 1.6 version of javac, then what is the version of the servlet-api.jar file in your downloads directory?
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes when I give java -version I get java version "1.6.0_04"
Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode)

And I have taken the servlet-api.jar from JBOSS folder.
How can I resolve this?
 
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
remove the servlet-api.jar file and download the new servlet-api.jar and set the class path
 
jagan raja
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for all your assistance.

Now its working fine.
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic