Forums Register Login

Correct cmd line javac for this file structure

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
Angus I have moved you to the servlets forum, as that is what you are creating now
+Pie Number of slices to send: Send
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 wasn't selected to go to mars. This tiny ad got in ahead of me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1820 times.
Similar Threads
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
Compiling custom imports
Tomcat WebApp Deployment
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:48:41.