• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot execute Head First Servlet & Jsp example

 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
R. Joshi
Greenhorn
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 22
Java MySQL Database Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will someone please help !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic