Angdi Chu Angdi Chu - 1 year ago 181
Java Question

Error while oprating javac -d: invalid flag? If I correct it, another package-not-found error appeared instead

I'm a newbie in Java EE. And I was following the steps of the book Head First Servlets and JSP to create a simple web application.

I wrote a simple servlet in Java. Now, I am planning to compile it and to put the class in the development environment. I'm not using any built tools, just with javac command in Windows. The servlet's path is D:\Learning Exercises\HeadFirstSnJ_Demo1\src\com\example\web\ And I plan to put the class file under the directory D:\Program Files (x86)\apache-tomcat-7.0.39\webapps\HeadFirstSnJ_Demo1\WEB_INF\classes\com\example\web\

The commands on the book are:

% cd MyProjects/beerV1
% javac -classpath /Users/bert/Applications2/tomcat/common/lib/servlet-api.jar:classes:. -d classes src/com/example/web/

I ran these command under Windows:

D:\>cd D:\Learning Exercises\HeadFirstSnJ_Demo1\src\com\example\web
D:\Learning Exercises\HeadFirstSnJ_Demo1\src\com\example\web>javac -classpath D:/"Program Files (x86)"/apache-tomcat-7.0.39/lib/servelt-api.jar;-d D:/"Program Files (x86)"/apache-tomcat-7.0.39/webapps/HeadFirstSnJ_Demo1/WEB_INF/classes/com/example/web

The system return an invalid flag error to me (I'm using a non-English OS. The following information is translated to English by myself):

javac: Invalid: D:/Program Files (x86)/apache-tomcat-7.0.39/webapps/HeadFirstSnJ_Demo1/WEB_INF/classes/com/example/web
Usage: javac <options> <source files>
-help to list all the valid options

Why did that happened? Am I using this javac -classpath -d command in a wrong way?

Actually, I think there is something wrong with the ";" here in front of "-d". If I replace the ";" with a space, there won't be this invalid flag error, BUT a "package javax.servlet doesn't exist" error instead, which is realy confused since I include the servlet-api.jar right here!

The corrected codes go here:

D:\Learning Exercises\HeadFirstSnJ_Demo1\src\com\example\web>javac -classpath "D:\Program Files (x86)\apache-tomcat-7.0.39\lib\servelt-api.jar" -d "D:\Program Files (x86)\apache-tomcat-7.0.39\webapps\HeadFirstSnJ_Demo1\WEB_INF\classes\com\example\web"

Answer Source

The spelling of "servlet-api.jar" is wrong.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download