• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

compiling servlet

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I just started preparing for SCWCD.I tried running the first example from 'Head First' book.I wrote the program in the first chapter but could not compile it.This is the error

C:\project1>javac -classpath "c:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar" -d classes src\Ch1Servlet.java
src\Ch1Servlet.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.
public class Ch1Servlet extends HttpServlet


Help???

Thank You!
 
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your class path.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which version of Java are you using ? Try typing "java -version" at the prompt. Tomcat 6 needs at least Java 5.0.
 
praneeth kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

This is what i got when I gave java - version

java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)

What should i do now?

Thank You
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mmmmh. Please try "javac -version -verbose -classpath "c:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar" -d classes src\Ch1Servlet.java
 
praneeth kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Christophe

This is what I got.

javac: invalid flag: -version
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-help Print a synopsis of standard options


Thanks for your patience.Should I uninstall Tomcat 6.0 and install a earlier version or is there any other way to make this work?

Thank You
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Should I uninstall Tomcat 6.0 and install a earlier version or is there any other way to make this work?


No, you can leave it. Look into your PATH. Type "SET" at the command prompt, and make sure there's is no directory which has an old "javac.exe" in it. I suspect there's a directory in your PATH containing a different version of javac. For example, if you have installed Oracle in your machine, it might add its own directory in the PATH, which contains a java compiler.
 
praneeth kumar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I became very impatient and uninstalled Tomcat 6.0 and installed 5.5

I tried to run the same servet and now it appears to work fine.However,I will also do what you have suggested.

Thanks a lot for the help.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried to run the same servet and now it appears to work fine.


Because Tomcat 5.5 can be used with JDK versions prior to 1.4, so you may be able to compile now. But, yes, you should try to figure out why the 1.5 compiler is not being called on the command prompt. What you could also do is to call javac using its full path. For example, "D:\java\jdk1.5.0_07\bin\javac"
 
reply
    Bookmark Topic Watch Topic
  • New Topic