• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Newbie question: Going through Head First Servlets & JSP book

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I'm going through Head First Servlets & JSP book and I came across a question that I hope someone can help me understand. I'm sure it is quite simple.

The book sas to use the following statement to compile the servlet: javac -classpath /Tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/BeerSelect.java

However, it doesn't compile. I get several errors that javax.servlet.* does not exist, etc.

This statement works just fine: javac -classpath /Tomcat/common/lib/servlet-api.jar -d classes src/com/example/web/BeerSelect.java

You'll notice that I dropped the ":classes." from the statement.

Can someone help explain what the ":classes." is suppose to do?

Thanks,
Andrew
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Andrew,
Since this is more of a classpath issue, than a servlet specific issue, I'm going to move this thread to our Java in General forum where classpath and javac issues are normally discussed.

This FAQ entry has links to articles on setting up your classpath as well:
http://faq.javaranch.com/java/CompilingServlets
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your classpath is a list of directories and jar files that javac and the JVM use to locate your classes. On Windows machines the directories are separated with semi-colons ; On Unix machines, they are separated with colons :.


The first version contains a classpath with servlet-api.jar and your classes directory. Simple, one class examples will work without your classes directory being included in the classpath but, once you try to compile a class that has dependencies on other classes in your project, it won't work without it being there.
 
Andrew Rodriguez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea why adding ":classes:." would cause the error below?

Could something be wrong with my Windows path statement?

Thanks!

--------------------------------------------------
C:\MyProjects\beerV1>javac -classpath /Tomcat/common/lib/servlet-api.jar:classes
:. -d classes src/com/example/web/BeerSelect.java
src/com/example/web/BeerSelect.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
src/com/example/web/BeerSelect.java:4: package javax.servlet.http does not exist

import javax.servlet.http.*;
^
src/com/example/web/BeerSelect.java:7: cannot find symbol
symbol: class HttpServlet
public class BeerSelect extends HttpServlet {
^
src/com/example/web/BeerSelect.java:9: cannot find symbol
symbol : class HttpServletRequest
location: class com.example.web.BeerSelect
public void doPost (HttpServletRequest request,
^
src/com/example/web/BeerSelect.java:10: cannot find symbol
symbol : class HttpServletResponse
location: class com.example.web.BeerSelect
HttpServletResponse response)
^
src/com/example/web/BeerSelect.java:11: cannot find symbol
symbol : class ServletException
location: class com.example.web.BeerSelect
throws IOException, ServletException {
^
6 errors
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On Windows, the path separator character is ";", not ":". You have to use semicolons to separate classpath entries, or they all look like one big long (incorrect!) entry.
 
Andrew Rodriguez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah! I didn't read the first reply careful enough... Thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic