aspose file tools*
The moose likes Beginning Java and the fly likes Compile problem not finding package javax.servlet.http Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compile problem not finding package javax.servlet.http" Watch "Compile problem not finding package javax.servlet.http" New topic
Author

Compile problem not finding package javax.servlet.http

Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
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

Joined: Jan 13, 2009
Posts: 357
write your full javac command please


Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
It is worth having a look at our FAQ.
Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
At the command prompt I am typing:
C:\java> javac BeeServlet.java

That is all.

Thanks.
Jim
Jim Buechler
Greenhorn

Joined: Nov 18, 2008
Posts: 13
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

Joined: Jan 13, 2009
Posts: 357
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

Joined: Aug 16, 2005
Posts: 14272
    
  21

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.


    Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
    Jim Buechler
    Greenhorn

    Joined: Nov 18, 2008
    Posts: 13
    Thanks Jesper, I will try this later this afternoon.
    Jim Buechler
    Greenhorn

    Joined: Nov 18, 2008
    Posts: 13
    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

    Joined: Nov 18, 2008
    Posts: 13
    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

    Joined: Jan 29, 2009
    Posts: 11
    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

    Joined: Nov 18, 2008
    Posts: 13
    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

    Joined: Oct 13, 2005
    Posts: 39436
        
      28
    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Compile problem not finding package javax.servlet.http