• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

cannot compile servlet from commandline

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to compile my servlet class from the jdk bin directory and getting the following errors.i think my compiler is not recognizing the imports.Is there any problem with my classpath? (Scroll to see error trace)

javac -classpath C:/tomcat/common/lib/servlet-api.jar:classes:. -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstProject/src/com/example/web/BeerSelect.java


My servlet is at C:/Myprojects/FirstProject/src/com/example/web/BeerSelect.java
and my tomcat is at C:/tomcat/
and my current dir is :C:\Program Files\Java\jdk1.6.0_05\bin

Errors:
C:\Program Files\Java\jdk1.6.0_05\bin>javac -classpath C:/tomcat/common/lib/serv
let-api.jar:classes:. -d C:/Myprojects/FirstProject/classes C:/Myprojects/FirstP
roject/src/com/example/web/BeerSelect.java
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:1: package javax.
servlet does not exist
import javax.servlet.*;
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:2: package javax.
servlet.http does not exist
import javax.servlet.http.*;
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:5: cannot find sy
mbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class HttpServletRequest
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class HttpServletResponse
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
^
C:\Myprojects\FirstProject\src\com\example\web\BeerSelect.java:7: cannot find sy
mbol
symbol : class ServletException
location: class BeerSelect
public void doPost(HttpServletRequest request,HttpServletResponse response)throw
s IOException,ServletException{
 
Ranch Hand
Posts: 140
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running it on windows?

if yes, compile using this

javac -classpath "C:\tomcat\commons\lib\servlet-api.jar;classes" -d destFolder Sample.java
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, as kurt suggested, Jars and directories must be separated by semi-colons under Windows.
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
set the classpath for the SERVLETAPI.jar file properly.
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any luck amar ???
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic