• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie question: Going through Head First Servlets & JSP book  RSS feed

 
Andrew Rodriguez
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Ah! I didn't read the first reply careful enough... Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!