Hi, i have a simple webapp in the developperphase (as given in the book "Head First Servlets & JSP"). I have installed jdk 18.104.22.168 and jre 22.214.171.124 (public). And i have Tomcat 6.0.14 up and running. Now, i want to compile a servlet (see code at the end between "***") but the "import" command doesn't work, as it can't find the path. Here's the message by javac: "C:\WebAppsDev\beerV1>javac -d classes src/com/example/web/beerselect.java src\com\example\web\beerselect.java:3: package com.example.model does not exist import com.example.model.*; ^ 1 error" .
I have set the JAVA_HOME variable (Windows XP SP2) in the systemvariables and in the uservariables the following way: C:\Program Files\Java\jdk1.6.0_04
I am about to troubleshoot this for weeks, i can't get the thing running, thanks for a feedback, Patrick
Ok, i'm getting closer. When i enter the command you gave me, javac can't find the servlet-api.jar file, as my environment variables get overwritten. Therefore, i've entered the command below (see between ***) and then compiled. It worked, but i have one question left: what does the last path mean ("classes")? It must be relative to where i start the javac from, as the C:.... path is not indicated. Can you explain or give me a ink where i can read that? Kind regards, Patrick SAAR
Then, i enter the following to compile Beerselect.java and javac replies the following:
C:\WebAppsDev\beerV1>javac -d classes src/com/example/web/Beerselect.java src\com\example\web\Beerselect.java:3: package com.example.model does not exist
I've tried your proposal to enter the following, but then it can even not find servlet-api.jar and gives lots of other errors, but the error above is gone! How to proceed? Hall i add something to my "set CLASSPATH" command?
Joined: Mar 22, 2005
I generally recommend not use the CLASSPATH variable, but to use the -classpath command line switch instead. It gets tiresome after a while to keep adding entries to CLASSPATH every time you start a new project. Not to mention that class names may start to conflict with one another. But to a certain degree that's personal preference.
You should not put either C:\WebAppsDev\beerV1\classes\com\example\model nor classes in the CLASSPATH variable, but instead put C:\WebAppsDev\beerV1\classes. Then the classes directory is available no matter in which directory you happen to be in.
Also, I doubt that either C:\Program Files\Java\jdk1.6.0_04 or C:\WebappsDev do any good (or anything at all, actually). It's unlikely that class files reside in either of those directories (and if they do, I'd move them elsewhere). [ February 04, 2008: Message edited by: Ulf Dittmer ]
Joined: Oct 08, 2007
HI, great, i've taken away all the uneeded an here's the smallest line that works:
There's omne question left as the book indicates sth. bizarre to me. Here's the command (the "..." is up to each's own directory structure up to the Tomcat home directory): "javac -classpath /..../tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/Beerselect.java"
What does the ":classes:." mean? When i try that, it just gives errors. And what does the "classes" behind "-d" mean?
But anyhow, it all works, this is just for a deeper understanding. I thank ou greatly for your efficient help.
Kind regards, Patrick
Joined: Mar 22, 2005
What does the ":classes:." mean?
Unix-ish operating system (like Maxc OS X and Linux) use the colon to separate entries in a list of paths, whereas Windows uses the semicolon.
And what does the "classes" behind "-d" mean?
The -d switch determines the directory where class files are written. So "-d classes" means that the .class files should go into a directory called "classes" inside of the current directory. If you leave out the switch altogether, the files are written in the current directory.