Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems compiling packages #2 with JSP

 
marten kay
Ranch Hand
Posts: 188
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still have a problem on page 85 of Head First Servlets and JSP that I have not been able to figure out.

I can't help myself because I don�t fully understand the two class paths in the line.

javac -classpath "C:\Program Files\ApacheSoftwareFoundation\Tomcat\common\lib\servlet-api.jar:". -d classes src/com/examples/web/BeerSelect.java


Here is my what I have, and result

servlet-api at
C:\Program Files\ApacheSoftwareFoundation\Tomcat\common\lib\servlet-api.jar

model class at
C:\java\JSPHFprojects\beerV1\src\com\example\model\BeerExpert.java



servlet at
C:\java\JSPHFprojects\beerV1\src\com\example\web\ BeerSelect.java



Result is



any help much appreciated
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-d tells javac which directory to put teh generated classes into, you are telling it the directory is src/com/examples/web/BeerSelect.java, and javac is telling you there is no such directory.

if you type javac on the command line it will list out it options.

G
 
marten kay
Ranch Hand
Posts: 188
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I now understand that the -d tells compiler where to put the generated file, but doesn't compiler create the path if it does not exist?

What the result is saying, is that the compiler can't find the source file which is in

C:\java\JSPHFprojects\beerV1\src\com\example\web\BeerSelect.java

when calling the compiler using

C:\java\JSPHFprojects\beerV1>javac -classpath "C:\Program F ... servlet-api.jar:". -d classes src/com/examples/web/BeerSelect.java
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats a good point.
You need to use the -sourcepath option to tell javac where to find the soruce.

(i think)

G
 
marten kay
Ranch Hand
Posts: 188
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But
javac -classpath "C:\Program Files\ApacheSoftwareFoundation\Tomcat\common\lib\servlet-api.jar:". -d classes -sourcepath . src/com/examples/web/BeerSelect.java

and some variations, doesn't work either...
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try:


The Colon and . at the end of the classpath look wrong, perhaps it should be a semi colon between the " and the .

i.e.


Other then that I am not sure. I dont have the book to hand to try it myself.

G
[ June 18, 2007: Message edited by: Gavin Tranter ]
 
marten kay
Ranch Hand
Posts: 188
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Gavin, but still no luck



will try again tomorrow

[ June 18, 2007: Message edited by: marten kay ]
[ June 18, 2007: Message edited by: marten kay ]
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are your java files actual in:

src/com/examples/web/

and is src a sub directory of your current directory?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change the : to a ;
i.e.
javac -classpath "C:\Program Files\ApacheSoftwareFoundation\Tomcat\common\lib\servlet-api.jar;."

The : is used as a separator on unix/linux, but on Windows you need to change it to ;
 
marten kay
Ranch Hand
Posts: 188
Java jQuery Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much

the semi colon did the job

I also found a good resource javac arguments for window

Joanne, you are a star, tomorrow I will be able to turn the page to p86
 
Veeru Bond
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having the exactly same problem.
For me,
model@
D:\MyProjects\beerV1\src\com\example\model\BeerExpert.java
servlet@
D:\MyProjects\beerV1\src\com\example\web\BeerSelect.java
servlet-api@
C:\Tomcat\apache-tomcat-5.5.23\common\lib\servlet-api.jar
Now I am trying to compile using:
javac -classpath "C:\Tomcat\apache-tomcat-5.5.23\common\lib\servlet-api.jar;". -d classes -sourcepath src/com/examples/web/BeerSelect.java

Still it is not getting compiled giving the following error:

javac: no source files
Usage: javac <options> <source files>
use -help for a list of possible options

Please help.
Also I don't know the usage of . after "c:\Tomcat...\servlet-api.jar;"

~ Veeru
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic