aspose file tools*
The moose likes Beginning Java and the fly likes cannot execute Head First Servlet & Jsp example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot execute Head First Servlet & Jsp example" Watch "cannot execute Head First Servlet & Jsp example" New topic
Author

cannot execute Head First Servlet & Jsp example

R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

I am reading 3rd chapter of Head First Servlets & Jsp i.e. Mini MVC tutorial. I cannot execute the version two servlet i.e. with model. Initially the model was not compiling I somehow compiled it using -Xlns but with warnings, and then when i again tried to recompile the servlet it is showing that package " com.example.model" doesnot exist, but i created this myself & kept the class file of model inside it.

Also can anyone please explain the use of "classes:." in
javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar;classes:. -d classes src/com/example/web/BeerSelect.java

and what does classes mean in the above line. And why are we using servelt-api.jar in this way rather then in CLASSPATH. I am compiling using classpath, is there some drawback of using classpath..??
Ishan Pandya
Ranch Hand

Joined: Feb 06, 2012
Posts: 223

R. Joshi wrote:when i again tried to recompile the servlet it is showing that package " com.example.model" doesnot exist


from where are you compiling the servlet? I hope it is from the context root.

Also can anyone please explain the use of "classes:." in
javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar;classes:. -d classes src/com/example/web/BeerSelect.java


"classes:." tells the compiler to look at the java code in the classes directory and the current directory which is denoted by "."
"-d classes" means that the class file which is generated after compilation should be kept in the "classes" directory of your web app.

And why are we using servelt-api.jar in this way rather then in CLASSPATH. I am compiling using classpath, is there some drawback of using classpath..??


this classpath syntax is temporary to current compilation. the "CLASSPATH variable" which we set remains constant. So if you want the classpath only for current compilation then you should set the classpath through command prompt only through the above given way.

thanks Hope this clears..


OCPJP
R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

from where are you compiling the servlet?



as per the meaning of classes:. as told by you & as i understood, this is the command that i am using to compile the BeerServlet.java that is using BeerExpert.java ( model ).


D:\beerV1\src\com\example\web> javac -classpath "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14\lib\servlet-api.jar;D:\beerV1\classes\com\example\model:." BeerSelect.java

where " D:\beerrV1\classes\com\example\model " is the directory to be looked for BeerExpert.java

Also can you please tell why was the BeerExpert.java compiled with warnings, i compiled it through -Xlns command & had to create " com\example\model " package directory myself while " com\example\web " was created while compiling but only in case of " BeerSelect.java version one " as version two cannot be compiled.

In " -d classes src/com/example/web/BeerSelect.java " what is that " src\com\example/web/BeerSelect.java " doing because for compiling we need to be in the containing directory & then run the javac command. Because the directory in which clas file is to be made is specified in " -d classes " .
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

R. Joshi wrote:om\example\web> javac -classpath "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14\lib\servlet-api.jar;D:\beerV1\classes\com\example\model:." BeerSelect.java

On Windows, you need to use ; (semi-colon) instead of : (colon) to separate entries on the classpath.

So that should be:

"C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14\lib\servlet-api.jar;D:\beerV1\classes\com\example\model;."

Note the semi-colon between "model" and "." instead of the colon.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

"C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.14\lib\servlet-api.jar;D:\beerV1\classes\com\example\model;."


I have used this also but still its saying that the " package com.example.model " doesnot exist & is not compiling.
R. Joshi
Greenhorn

Joined: Jan 04, 2013
Posts: 22

will someone please help !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot execute Head First Servlet & Jsp example