| Author |
compiling servlet
|
praneeth kumar
Greenhorn
Joined: May 10, 2007
Posts: 20
|
|
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!
|
SCJP 1.5 - 91%
|
 |
dolly shah
Ranch Hand
Joined: Jun 18, 2007
Posts: 383
|
|
|
Check your class path.
|
SCJP-1.5<br />SCWCD-1.4
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
|
Which version of Java are you using ? Try typing "java -version" at the prompt. Tomcat 6 needs at least Java 5.0.
|
[My Blog]
All roads lead to JavaRanch
|
 |
praneeth kumar
Greenhorn
Joined: May 10, 2007
Posts: 20
|
|
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
Joined: Nov 24, 2005
Posts: 14685
|
|
|
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
Joined: May 10, 2007
Posts: 20
|
|
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
Joined: Nov 24, 2005
Posts: 14685
|
|
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
Joined: May 10, 2007
Posts: 20
|
|
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
Joined: Nov 24, 2005
Posts: 14685
|
|
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"
|
 |
 |
|
|
subject: compiling servlet
|
|
|