my dog learned polymorphism*
The moose likes Servlets and the fly likes Servlet compile problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet compile problem" Watch "Servlet compile problem" New topic
Author

Servlet compile problem

thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
Hi all,

I am trying to follow the code example in HeadFirst Servlet and JSP book to compile the first servlet (BeerSelect.java), although every time I enter the following command in the terminal:

javac -classpath /usr/share/tomcat6/lib/servlet-api.jar:classes:. -d classes home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

I get either one of two errors:
- javac: file not found: home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

or

- javac: directory not found: classes

So can someone please tell me what exactly I am doing wrong here?

Thanks in advance for your time

Note: I am running tomcat 6 (latest) under Ubuntu 10 with Java 6
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

You're forgetting to begin the path to your Java file with a slash: "/home/pav/..."

Also, why are you including the "classes" directory in your classpath when compiling...?? This is the directory you are storing the compiled class files in. You need these files to run the program, but not to compile it because compiling it is what creates these files in the first place!


SCJP 6 || SCWCD 5
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Unless there's a dependency.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Dependency? The "classes" directory he's including in the classpath is the one he's saving his compiled class files to. It makes no sense to include this in the classpath.
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
Hi All,

Thanks a lot for your help and time...please find my replies below:

Michael Angstadt: When I added the splash before home to be /home/pav, I got an error message:
javac: directory not found: classes

I am including classes as per the book, this line should compile and produce the new java class in the corresponding class directory

Now I tried again to remove classes from the line, to make it like this:

javac -classpath /usr/share/tomcat6/lib/servlet-api.jar:classes:. -d /home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

and I got error:
javac: not a directory: /home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

Any ideas will be highly appreciated

Note: please excuse me if my mistakes are silly but I am quite new...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617


and I got error:
javac: not a directory: /home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

Well, it's not; it's a Java source file. "-d" signifies the output directory.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

No no no, remove "classes" from the classpath.

javac -classpath /usr/share/tomcat6/lib/servlet-api.jar:. -d classes SPLASHhome/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
Hi all,

Thanks for your replies, actually I have removed -d classes totally from the line so that it will be:

javac -classpath /usr/share/tomcat6/lib/servlet-api.jar:classes. /home/pav/MyJava/Workspace/beerV1/src/com/example/web/BeerSelect.java

and it finally worked! Yet I am still confused why it didn't accept the -d directive?!!

Another amazing issue I've just found in this code is that now after it was compiled, and I've placed it exactly in the place they mentioned in the book, under tomcat/project directory/WEB-INF/classes when I try to load the project form using:

http://localhost:8080/Beer-V1/form.html

it simply loads HTTP Status 404 - /Beer-V1/form.html with a description, the requested resource (/Beer-V1/form.html) is not available

Any help will be highly appreciated, all I am seeking here is to see how this works
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please show us the actual Tomcat directory hierarchy and the web.xml. It's important to TellTheDetails, otherwise it's impossible for us to help.
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
David Newton wrote:Please show us the actual Tomcat directory hierarchy and the web.xml. It's important to TellTheDetails, otherwise it's impossible for us to help.


Thanks David for your reply, please find attached a screenshot for the Tomcat directory hierarchy, showing form.html which I am trying to load..

Also please find below code inside form.html




Please let me know if I should post any other info that can help, I am new here so I might not know everything that should be posted to help clarify my exact problem

Thanks in advance for your patience and time



[Thumbnail for tomcat.png]

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

David Newton wrote:Please show us the [...] the web.xml.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I see no class files in your directory structure. But for non-pictures, please use text; it's a lot more convenient. Thanks!
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
Hi David,

Please find below the content of web.xml




Regarding classes, actually what's amazing here is that the book said that I should see the content of form.html even before compiling any class...which is what I am trying to do without any success

But anyway, there is only one class under /com/example/web/ folder with the name BeerSelect.class

This class java code is as follows:



Thanks in advance for your time
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Check the startup logs for any errors. Oh, and use the same case in the URL that you use for the directory name--you've shown /Beer-V1 instead of /Beer-v1 as your directory listing shows.
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
David Newton wrote:Check the startup logs for any errors. Oh, and use the same case in the URL that you use for the directory name--you've shown /Beer-V1 instead of /Beer-v1 as your directory listing shows.


Can you please elaborate what type of 'startup logs' you are pointing to? and if possible where they are located so that I can check them

I've already tried with /Beer-V1 and /Beer-v1 and even /beer-v1 and none of them worked

So any ideas?

Thanks in advance for your time and efforts
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
David,

I've searched the web for any reference to 'start logs' under Tomcat, or java and couldn't find anything...so can you please elaborate what are those 'start logs'?

Thanks in advance for your time
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Tomcat has a log (two, actually) under the "logs" directory. If there are startup errors, they're in those logs. Knowing about logging is very important.
thirun pavan
Greenhorn

Joined: Jun 27, 2007
Posts: 22
Hi David,

I found two log files under /var/log/tomcat6/:

1. catalina.2010-08-03.log which happened to contain the following:


2. localhost.2010-08-03.log which happened to contain the following:


Keeping in consideration that I have no experience reading tomcat log files, I am not sure if it indicate any problem....so any idea what might be wrong in those log files? In other words doe they indicate any problem?

Thanks in advance for your time
 
 
subject: Servlet compile problem
 
Similar Threads
Classpath in Command line
package does not exist problem
Package does not exist
Head First Servlets & JSP: Can't compile second version of BeerSelect.java
Package problems