Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling servlet giving error message

Tags:

java

servlets

I ran the following command to compile a servlet called BeerSelect.java from HeadFirst Servlets and JSP book.

D:\Apache Tomcat\apache-tomcat-5.5.36\apache-tomcat-5.5.36\webapps\Coffee>javac -classpath /common/lib servlet-api.jar:classes: -d classes src/com/example/web/B eerSelect.java

My servlet-api.jar is located in D:\Apache Tomcat\apache-tomcat-5.5.36\apache-tomcat-5.5.36\common\lib

MESSAGE

javac: invalid flag: servlet-api.jar:classes:
Usage: javac <options> <source files> use -help for a list of possible options

Cannot understand how to fix this command and compile the servlet. Doing it for the first time new to servlets.

Then I changed the command to be

D:\Apache Tomcat\apache-tomcat-5.5.36\apache-tomcat-5.5.36\webapps\Coffee\WEB-IN
F\src\com\example\web>javac -classpath "D:\Apache Tomcat\apache-tomcat-5.5.36\ap
ache-tomcat-5.5.36\common\lib\servlet-api.jar";classes  BeerSelect.java

MESSAGE

BeerSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
BeerSelect.java:15: cannot find symbol
symbol  : class BeerExpert
location: class com.example.web.BeerSelect
        BeerExpert be = new BeerExpert();
        ^
BeerSelect.java:15: cannot find symbol
symbol  : class BeerExpert
location: class com.example.web.BeerSelect
        BeerExpert be = new BeerExpert();
                            ^
BeerSelect.java:32: cannot find symbol
symbol  : variable out
location: class com.example.web.BeerSelect
         out.println("<br>try: " + it.next());
         ^
4 errors

Why cannot it find the com.example.model package ?

IMAGEenter image description here

like image 595
MindBrain Avatar asked May 24 '26 18:05

MindBrain


1 Answers

It looks like you have three issues with your command: extra spaces, Unix-style pathnames, and missing additional Java source files. Try the following instead:

javac -classpath "D:\Apache Tomcat\apache-tomcat-5.5.36\apache-tomcat-5.5.36\common\lib\servlet-api.jar";classes -d classes src\com\example\web\*.java src\com\example\model\*.java

I've removed extra spaces, converted Unix paths to Windows paths, changed the classpath separator from the Unix-style ':' to Windows-style ';', and added your other Java sources - compiling them all together should resolve your first three compiler errors.

As for the last compiler error, that appears to be a genuine source code error - try prepending System. to the out.println("<br>try: " + it.next()); line. (It can also be resolved by a static import, but that would be unconventional.)

like image 77
Mark A. Fitzgerald Avatar answered May 26 '26 09:05

Mark A. Fitzgerald