Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compile problem not finding package javax.servlet.http

 
Jim Buechler
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having a compile problem with javac. I just downloaded J EE 5 SDK from Sun and added it to the CLASSPATH variable, but my servlet will not compile due to package javax.servlet.http does not exist. My classpath is as follows:

C:\Sun\SDK\jdk\jre\lib\rt.jar; c:\Sun\SDK\lib\j2ee.jar; c:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar;c:\StudentWork\jr.jar

Does anyone have any suggestions?

Thanks.
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write your full javac command please
 
Campbell Ritchie
Sheriff
Pie
Posts: 49432
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is worth having a look at our FAQ.
 
Jim Buechler
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the command prompt I am typing:
C:\java> javac BeeServlet.java

That is all.

Thanks.
Jim
 
Jim Buechler
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I look at the FAQ and wasn't able to find anything I have not done. I have the j2ee.jar in the classpath and the import statement is correct, so I'm not sure what the issue is.

Thanks.
Jim
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you assume that you don't have anythong wrong we can't help. How are we supposed to know the problem if you don't show us how are you doing it? We don't do magics, at least give us some logs.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Sun\SDK\jdk\jre\lib\rt.jar; c:\Sun\SDK\lib\j2ee.jar; c:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar;c:\StudentWork\jr.jar


  • You have spaces in the classpath that should not be there. Do not put a space between the ; and the C:\ of the next JAR in the classpath.
  • You should not put rt.jar from the JDK in the classpath; it's unnecessary.
  • Also, it's a good idea to put ".", which indicates "the current directory", in the classpath.


  • Change it to:

    c:\Sun\SDK\lib\j2ee.jar;c:\Program Files\Apache Tomcat 4.0\common\lib\servlet.jar;c:\StudentWork\jr.jar;.

    Also, check if all those JAR files really exist in the locations that you've specified in the classpath.
     
    Jim Buechler
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Jesper, I will try this later this afternoon.
     
    Jim Buechler
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Jesper, I tried changing the classpath but got the same message. Here's my new classpath:

    c:\Sun\SDK\lib\j2ee.jar;.;c:\StudentWork\jr.jar

    By the way, I would like to send you the log, but I was not able to copy it from my DOS prompt console and paste it here. Any ideas?

    Thanks.
    Jim
     
    Jim Buechler
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ah, I figured out how to paste the log, here it is

    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Owner>cd c:\java

    C:\java>javac BeeServlet.java
    BeeServlet.java:2: package javax.servlet.http does not exist
    import javax.servlet.http.* ;
    ^
    BeeServlet.java:4: cannot resolve symbol
    symbol : class HttpServlet
    location: class BeeServlet
    public class BeeServlet extends HttpServlet
    ^
    BeeServlet.java:7: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class BeeServlet
    public void doGet( HttpServletRequest request , HttpServletResponse re
    sponse )
    ^
    BeeServlet.java:7: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class BeeServlet
    public void doGet( HttpServletRequest request , HttpServletResponse re
    sponse )
    ^
    4 errors

    C:\java>

    C:\java>
     
    Gurjit Sandhu
    Greenhorn
    Posts: 11
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The Servlet can be compiled the same way as any other Java source file. You can compile
    it from the command line using javac, or if you are using an integrated development environment
    (IDE), use the IDE’s compile command or menu option. You will need to include the
    correct Java EE library for the compilation. There are two possible libraries to choose from,
    depending on whether you are using the Java EE reference implementation, the Tomcat server,
    or JBoss. It doesn’t matter which one you use. If you have the Java EE SDK, you can use the
    javaee.jar library; if you have Tomcat or JBoss (which uses Tomcat), you can use servlet-api.jar.
    For example, if you’re using the Java EE reference implementation, assuming JAVAEE_HOME
    is the environment variable for the location of the Java EE SDK, you could compile the Servlet
    with the following command line on Windows systems:
    > javac –classpath %JAVAEEHOME%\lib\javaee.jar Login.java
    On Linux and Unix systems, you would use this command line:
    > javac –classpath $JAVAEEHOME/lib/javaee.jar Login.java
    If you’re using Tomcat 5, assuming CATALINA_HOME is the location of the Tomcat installation,
    on Windows systems, compile the Servlet with the following command:
    > javac –classpath %CATALINA_HOME%\common\lib\servlet-api.jar Login.java
    On Linux and Unix systems, use this command:
    > javac –classpath $CATALINA_HOME/common/lib/servlet-api.jar Login.java
     
    Jim Buechler
    Greenhorn
    Posts: 13
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Guys, I was able to compile my servlet.

    What I did was change the Path variable.

    Originally it was as follows:
    C:\java>set p
    Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;c:\j2sdk1.4.2_05\bin;C:\Sun\SDK\bin;C:\Sun\AppServer\bin

    I removed c:\j2sdk1.4.2_05\bin
    and added C:\Sun\SDK\jdk\bin

    My new Path variables look like this:
    C:\java>echo %path%
    C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;C:\Sun\SDK\bin;C:\Sun\AppServer\bin;C:\Sun\SDK\jdk\bin

    This is my classpath which has remained the same:
    C:\java>echo %classpath%
    c:\Sun\SDK\lib\j2ee.jar;.;c:\StudentWork\jr.jar

    I am not sure why this works now except that the j2sdk1.4.2_05\bin was not compatible with J EE 5 SDK I downloaded. Am I thinking correctly? Can anyone offer insight?

    Thanks.
    Jim
     
    Campbell Ritchie
    Sheriff
    Pie
    Posts: 49432
    62
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Since Java 1.4.2 was superseded by Java 5 in Autumn 2004, and I think J2EE5 is more recent, that might well be the problem.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic