• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet compile problem

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless there's a dependency.
 
Michael Angstadt
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
tomcat.png
[Thumbnail for tomcat.png]
screenshot for tomcat directory structure
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic