Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Correct cmd line javac for this file structure

 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angus I have moved you to the servlets forum, as that is what you are creating now
 
Angus Comber
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic