Solved

Cannot compile Java serlvet code

Posted on 2014-11-13
7
551 Views
Last Modified: 2014-11-13
I am trying to compile the Java code HelloServlet.java HelloServlet.java on my windows 7 PC:

I am following the directions at http://www.cis.upenn.edu/~cis330/jetty.html
I am getting error at compilation as below. Could you please assist me to compile?

C:\jetty\jetty-6.1.11\jetty-6.1.11>where javac
C:\Program Files\Java\jdk1.8.0_25\bin\javac.exe
C:\jetty\jetty-6.1.11\jetty-6.1.11>echo %JAVA_HOME%
C:\Program Files\Java\jdk1.8.0_25

C:\jetty\jetty-6.1.11\jetty-6.1.11>dir
 Volume in drive C has no label.
 Volume Serial Number is E609-E068

 Directory of C:\jetty\jetty-6.1.11\jetty-6.1.11

11/13/2014  09:51 AM    <DIR>          .
11/13/2014  09:51 AM    <DIR>          ..
11/12/2014  03:32 PM    <DIR>          bin
11/12/2014  03:32 PM    <DIR>          contexts
11/12/2014  03:32 PM    <DIR>          contrib
11/12/2014  03:32 PM    <DIR>          etc
11/12/2014  03:32 PM    <DIR>          examples
11/12/2014  03:32 PM    <DIR>          extras
11/13/2014  09:48 AM               983 HelloServlet.java
11/12/2014  03:32 PM    <DIR>          javadoc
11/12/2014  03:32 PM    <DIR>          lib
11/12/2014  03:32 PM    <DIR>          LICENSES
11/12/2014  04:48 PM    <DIR>          logs
11/12/2014  03:32 PM    <DIR>          modules
11/12/2014  03:32 PM    <DIR>          patches
11/12/2014  03:32 PM            12,512 pom.xml
11/12/2014  03:32 PM    <DIR>          project-website
11/12/2014  03:32 PM             4,253 README.txt
11/12/2014  03:32 PM    <DIR>          resources
11/12/2014  03:32 PM            16,501 start.jar
11/12/2014  03:32 PM           141,436 VERSION.txt
11/12/2014  05:07 PM    <DIR>          webapps
               5 File(s)        175,685 bytes
              17 Dir(s)  119,868,235,776 bytes free

C:\jetty\jetty-6.1.11\jetty-6.1.11>

C:\jetty\jetty-6.1.11\jetty-6.1.11\lib>dir
 Volume in drive C has no label.
 Volume Serial Number is E609-E068

 Directory of C:\jetty\jetty-6.1.11\jetty-6.1.11\lib

11/12/2014  03:32 PM    <DIR>          .
11/12/2014  03:32 PM    <DIR>          ..
11/12/2014  03:32 PM    <DIR>          annotations
11/12/2014  03:32 PM    <DIR>          cometd
11/12/2014  03:32 PM    <DIR>          ext
11/12/2014  03:32 PM           500,194 jetty-6.1.11.jar
11/12/2014  03:32 PM           160,510 jetty-util-6.1.11.jar
11/12/2014  03:32 PM    <DIR>          jsp-2.0
11/12/2014  03:32 PM    <DIR>          jsp-2.1
11/12/2014  03:32 PM    <DIR>          management
11/12/2014  03:32 PM    <DIR>          naming
11/12/2014  03:32 PM    <DIR>          plus
11/12/2014  03:32 PM           132,417 servlet-api-2.5-6.1.11.jar
11/12/2014  03:32 PM    <DIR>          win32
11/12/2014  03:32 PM    <DIR>          xbean
               3 File(s)        793,121 bytes
              12 Dir(s)  119,868,227,584 bytes free

C:\jetty\jetty-6.1.11\jetty-6.1.11\lib>

C:\jetty\jetty-6.1.11\jetty-6.1.11>javac -cp C:\jetty\jetty-6.1.11\jetty-6.1.11\
lib\servlet-api-2.5-6.1.11\servlet-api-2.5-6.1.11.jar HelloServlet.java
HelloServlet.java:2: error: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:3: error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServlet.java:5: error: cannot find symbol
public class HelloServlet extends HttpServlet
                                  ^
  symbol: class HttpServlet
HelloServlet.java:7: error: cannot find symbol
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                         ^
  symbol:   class HttpServletRequest
  location: class HelloServlet
HelloServlet.java:7: error: cannot find symbol
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                                                 ^
  symbol:   class HttpServletResponse
  location: class HelloServlet
HelloServlet.java:8: error: cannot find symbol
        throws ServletException, IOException
               ^
  symbol:   class ServletException
  location: class HelloServlet
HelloServlet.java:20: error: cannot find symbol
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                          ^
  symbol:   class HttpServletRequest
  location: class HelloServlet
HelloServlet.java:20: error: cannot find symbol
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                                                  ^
  symbol:   class HttpServletResponse
  location: class HelloServlet
HelloServlet.java:21: error: cannot find symbol
        throws ServletException, IOException
               ^
  symbol:   class ServletException
  location: class HelloServlet
9 errors

C:\jetty\jetty-6.1.11\jetty-6.1.11>
0
Comment
Question by:toooki
  • 4
  • 2
7 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 40440658
C:\jetty\jetty-6.1.11\jetty-6.1.11>dir /ad/s/b webapps

Open in new window


please post output of above
0
 

Author Comment

by:toooki
ID: 40440669
Thanks. Here it is:
C:\jetty\jetty-6.1.11\jetty-6.1.11>dir /ad/s/b webapps
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\hello
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\hello\WEB-INF
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\hello\WEB-INF\classes
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\auth
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\cgi-bin
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\chat
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\js
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\jsp
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\WEB-INF
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\WEB-INF\classes
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\WEB-INF\tags
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\WEB-INF\classes\com
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test\WEB-INF\classes\com\acme
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas\META-INF
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas\WEB-INF
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas\META-INF\maven
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas\META-INF\maven\org.mortbay.
jetty
C:\jetty\jetty-6.1.11\jetty-6.1.11\webapps\test-jaas\META-INF\maven\org.mortbay.
jetty\jetty-test-jaas

C:\jetty\jetty-6.1.11\jetty-6.1.11>

Open in new window

0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 40440711
Try

C:\jetty\jetty-6.1.11\jetty-6.1.11>mkdir source
C:\jetty\jetty-6.1.11\jetty-6.1.11>move HelloServlet.java source
C:\jetty\jetty-6.1.11\jetty-6.1.11>cd source
C:\jetty\jetty-6.1.11\jetty-6.1.11\source>javac -d ..\webapps\hello\WEB-INF\classes -classpath ..\lib\servlet-api-2.5-6.1.11.jar;. HelloServlet.java
C:\jetty\jetty-6.1.11\jetty-6.1.11\source>echo 'Is it there?'
C:\jetty\jetty-6.1.11\jetty-6.1.11\source>dir /b ..\webapps\hello\WEB-INF\classes

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 9

Accepted Solution

by:
arioh earned 250 total points
ID: 40440795
you have wrong extra path in your javac parameters (C:\jetty\jetty-6.1.11\jetty-6.1.11\lib\servlet-api-2.5-6.1.11\servlet-api-2.5-6.1.11.jar)

try this one
C:\jetty\jetty-6.1.11\jetty-6.1.11>javac -cp .\lib\servlet-api-2.5-6.1.11.jar HelloServlet.java
0
 

Author Comment

by:toooki
ID: 40440838
It worked. Many thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40440858
What did? ;)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40441336
The problem is that won't put the class file where it's meant to be. OK, so you can copy the class file or move it but
a. there's no need
b. if you have packages involved (which you should normally) that won't be easy

If you want to continue at the command line (which personally i think is a good idea), you might like to look at using Ant, which will cope as the classpath gets bigger
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 43
by zero exception 10 41
ejb on wildfly 5 20
Adding multiple JVM environments to RedHat 6 7 24
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question