Results 1 to 5 of 5
  1. #1
    paul21 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default .java won't compile

    I'm having trouble getting a simple .java to compile

    Java Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class HelloWorld extends HttpServlet {
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println( "<HTML> <BODY> <H1>Hello World !</H1> </BODY></HTML>");
      }
    }
    here are the error

    Java Code:
    paul@paul-laptop:~$ javac -cp . HelloWorld.java 
    HelloWorld.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloWorld.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloWorld.java:5: cannot find symbol
    symbol: class HttpServlet
    public class HelloWorld extends HttpServlet {
                                    ^
    HelloWorld.java:6: cannot find symbol
    symbol  : class HttpServletRequest
    location: class HelloWorld
      public void doGet(HttpServletRequest request,
                        ^
    HelloWorld.java:7: cannot find symbol
    symbol  : class HttpServletResponse
    location: class HelloWorld
                        HttpServletResponse response)
                        ^
    HelloWorld.java:8: cannot find symbol
    symbol  : class ServletException
    location: class HelloWorld
          throws ServletException, IOException {
                 ^
    6 errors
    here is the classpath location

    Java Code:
    paul@paul-laptop:~$ echo $CLASSPATH
    /home/paul/apache-tomcat-6.0.18/lib/servlet-api.jar:/home/paul/apache-tomcat-6.0.18/lib/jsp-api.jar

    any ideas why this will not compile

  2. #2
    paul21 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default

    solved

    I used
    Java Code:
    javac
    when before i was using
    Java Code:
     javac -cp . HelloWorld.java
    Anyone any idea why it wansn't working to begin with as javac -cp . should work

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    The -cp option overrides the CLASSPATH environment variable. When you did '-cp .' you wiped out the Tomcat directories in your CLASSPATH.

    -Gary-

  4. #4
    Phemosky is offline Member
    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Default

    i will advice you to go and download netbeans with web application to be able to run your servlets

  5. #5
    javastuden's Avatar
    javastuden is offline Senior Member
    Join Date
    Nov 2009
    Posts
    162
    Rep Power
    6

    Default

    hi,
    you has to compile with the jar file with -cp option
    like this
    C:\Documents and Settings\Desktop>javac -cp "D:/samples/javax.servlet.jar" HelloWorld.java
    this is windows i dont know how the same doing in linus based patforms
    ok

    you will get the jar from http://www.java2s.com/Code/Jar/STUVW...servletjar.htm
    Last edited by javastuden; 03-30-2010 at 07:59 AM. Reason: add

Similar Threads

  1. New to JAVA and code cant compile
    By Gayethiri_86 in forum New To Java
    Replies: 2
    Last Post: 03-05-2010, 07:43 AM
  2. Compile and Run a Java package
    By hussain in forum New To Java
    Replies: 1
    Last Post: 09-10-2009, 10:15 AM
  3. Replies: 5
    Last Post: 03-26-2009, 07:24 AM
  4. My Java program will not compile and run?
    By sabrown311313 in forum Java Applets
    Replies: 1
    Last Post: 09-23-2008, 10:38 AM
  5. Help with Java Compile File
    By baltimore in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •