wood burning stoves 2.0*
The moose likes Servlets and the fly likes Correct cmd line javac for this file structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Correct cmd line javac for this file structure" Watch "Correct cmd line javac for this file structure" New topic
Author

Correct cmd line javac for this file structure

Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
I am creating my first servlet by hand (ie not using eclipse) and am trying to follow the explanation in Head First Servlets ch3 page 81.

File structure is like this:

I am running command from \tomcat-7\webapps\Beer-v1\ folder.

jar file I need in classpath is \tomcat-7\lib\servlet-api.jar

For the exercise I have created this folder:
\tomcat-7\webapps\Beer-v1\WEB-INF\classes\com\example\web\ (but nothing yet in this folder)

I am running on Windows so at \tomcat\webapps\Beer-v1\ folder I tried:
M:\java\java_web_programming\tomcat-7\webapps\Beer-v1>javac -classpath M:\java\j
ava_web_programming\tomcat-7\lib\servlet-api.jar;classes;. -d ./WEB-INF/classes
BeerSelect.java

And that created a class file in WEB-INF/classes

Is that the correct place for them?

I don't mind changing the structure - just using what is recommended in book.

Can anyone help?
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Angus I have moved you to the servlets forum, as that is what you are creating now
Angus Comber
Ranch Hand

Joined: Jul 16, 2011
Posts: 90
If anyone is struggling to do the same here is what i found worked.

This in Windows platform where path separator is \ and delimitter is ; (if you are on unix or mac path separator is / and delim is : )

tomcat is installed in C:\java_web_programming\tomcat-7.0 folder.

I created C:\java_web_programming\tomcat-7.0\webapps\Beer-v1\classes\com\example\web folder.

Source files package statement is: package com.example.web;

Compile like this:-
javac -classpath C:\java_web_programming\tomcat-7.0\lib\servlet-api.jar -d classes src\com\example\web\BeerSelect.java

This creates classes\com\example\web\BeerSelect.class


I still have more to do however because in web page I now see:

HTTP Status 500 - Error instantiating servlet class com.example.web.BeerSelect

type Exception report

message Error instantiating servlet class com.example.web.BeerSelect

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class com.example.web.BeerSelect
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

root cause

java.lang.ClassNotFoundException: com.example.web.BeerSelect
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

Anyone any ideas on how to solve that?

EDIT:

Last step is to copy class file to WEB-INF\classes\com\example\web

I thought Beer-v1\classes\com\example\web was ok - but no.

Then it works
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Correct cmd line javac for this file structure
 
Similar Threads
Tomcat WebApp Deployment
Compiling custom imports
HFS: Problem with deploying and testing Beer-v1 App
Getting package and class exceptions with the BeerAcvice web app!!! Pls Help
Servlet in Package Issue