当oprating javac -d:无效标志时发生错误?如果我纠正了它,另一个没有发现的错误出现了。

时间:2021-12-24 04:50:44

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.

我是Java EE的新手。我正按照书头的第一个servlet和JSP的步骤创建一个简单的web应用程序。

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\BeerSelect.java. 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\

我在Java中编写了一个简单的servlet。现在,我打算编译它并将类放到开发环境中。我没有使用任何构建工具,只是在Windows中使用javac命令。这个servlet的路径是D:\学习训练\HeadFirstSnJ_Demo1\src\ web\BeerSelect.java。我打算把类文件放在D:\程序文件(x86)\apache-tomcat-7.0.39\webapps\ web_demo1 \WEB_INF\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

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/BeerSelect.java

I ran these command under Windows:

我在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 BeerSelect.java

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?

为什么,发生了什么?我是否用错误的方式使用了这个javac -classpath -d命令?

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!

实际上,我认为“”在前面的“-d”是有问题的。如果我用空格替换“;”,就不会出现这个无效的标记错误,而是一个“包javax”。servlet不存在“错误,因为我包含了servlet-api,所以很混乱。jar这里!

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" BeerSelect.java

3 个解决方案

#1


2  

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

的拼写”servlet api。jar”是错误的。

#2


0  

Use your directory navigation this way

用这种方法使用目录导航。

"D:/Program Files (x86)/apache-tomcat-7.0.39/lib/servelt-api.jar"

#3


0  

Use '\' for directory navigation in windows. [ '/' is for linux]. So try this:

在windows中使用“\”目录导航。['/'是针对linux的]。那么试试这个:

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 BeerSelect.java

#1


2  

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

的拼写”servlet api。jar”是错误的。

#2


0  

Use your directory navigation this way

用这种方法使用目录导航。

"D:/Program Files (x86)/apache-tomcat-7.0.39/lib/servelt-api.jar"

#3


0  

Use '\' for directory navigation in windows. [ '/' is for linux]. So try this:

在windows中使用“\”目录导航。['/'是针对linux的]。那么试试这个:

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 BeerSelect.java