简体   繁体   English

编译Servlet时出错:找不到文件

[英]Error compiling servlet: file not found

I'm trying to compile a servlet called BeerSelect.java and I'm getting this error: 我正在尝试编译一个名为BeerSelect.javaservlet ,但出现此错误:

javac: file not found: BeerSelect.java

I compiled using: javac -classpath "C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.34\\lib\\servlet-api.jar"; -d classes \\BeerSelect.java 我使用以下命令进行编译:javac -classpath "C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.34\\lib\\servlet-api.jar"; -d classes \\BeerSelect.java "C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.34\\lib\\servlet-api.jar"; -d classes \\BeerSelect.java

I used this command to compile with my current directory set to where the servlet is stored, my class path is set correctly. 我使用此命令将当前目录设置为servlet的存储位置,并且正确设置了我的类路径。

I checked many related questions on this site and cannot get the answer 我在此网站上检查了许多相关问题,但无法获得答案

You shouldn't set your classpath to point to your JDK bin directory -- instead it should be the PATH environment variable, which serves a different purpose to classpath. 您不应将类路径设置为指向您的JDK bin目录-而是应该是PATH环境变量,它与类路径的作用不同。 (The classpath defines a list of jars and directories containing compiled Java .class code; the PATH variable defines a list of paths where the shell needs to look and locate programs to execute when they are not found in the current directory -- so if you type for instance zip -- it would look in all the directories defined in PATH and figure out that zip program is located under /usr/bin) Secondly if you want to compile sources from both directory you need to specify: (类路径定义了包含已编译的Java .class代码的jar和目录的列表; PATH变量定义了路径的列表,外壳程序需要在其中查找和定位在当前目录中找不到它们时要执行的程序,因此,如果您输入例如zip的类型-它会查看PATH中定义的所有目录,并找出zip程序位于/ usr / bin下)其次,如果要从这两个目录编译源,则需要指定:

all the paths where the sources are (both home/pathToFolderA/src and home/pathToFolderB/gen-java) the path where the compiled .class files to be generated specify in the classpath any library you might use in your source files To sum it up, it would be something like this to compile: 源所在的所有路径(home / pathToFolderA / src和home / pathToFolderB / gen-java)要生成的已编译.class文件的路径在类路径中指定了您可以在源文件中使用的任何库以求和向上,将像这样编译:

javac -d /home/pathToFolderWithResultsOfCompilation -classpath /path/to/some.jar:/path/to/another.jar home/pathToFolderA/src/*.java home/pathToFolderB/gen-java/*.java 

and to run your compiled programs: 并运行您的编译程序:

java -classpath /path/to/some.jar:/path/to/another.jar:/home/pathToFolderWithResultsOfCompilation full.name.of.your.Java

The problem with the command i was using: 我正在使用的命令的问题:
javac -classpath "C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.34\\lib\\servlet-api.jar"; javac -classpath“ C:\\ Program Files \\ Apache Software Foundation \\ Apache Tomcat 7.0.34 \\ lib \\ servlet-api.jar”; -d classes \\BeerSelect.java -d \\ BeerSelect.java

is with the path name to store the results of compilation (.class file) and putting a backslash on the BeerSelect servlet name (i highlighted the errors). 使用路径名来存储编译结果(.class文件),并在BeerSelect servlet名称上加上反斜杠(我突出显示了错误)。 I refined the command to look like this: 我优化了命令,使其看起来像这样:

javac -d C:\\Users\\ModernWarFare\\Desktop\\MyProject\\beerV1\\classes BeerSelect.java javac -d C:\\ Users \\ ModernWarFare \\ Desktop \\ MyProject \\ beerV1 \\ classes BeerSelect.java

the highlited path is where i'm going to store the .class file and i didn't specify the path to the BeerSelect.java file because it is in the current directory 高亮路径是我要存储.class文件的位置,并且我没有指定BeerSelect.java文件的路径,因为它位于当前目录中

note that i ommited the path to the servlet-api.jar file because i am using tomcat 7, it already have all the jar files i need stored on C:\\Program Files\\Apache Software Foundation\\Apache Tomcat 7.0.34\\lib directory. 请注意,我省略了servlet-api.jar文件的路径,因为我使用的是tomcat 7,它已经将我需要的所有jar文件存储在C:\\ Program Files \\ Apache Software Foundation \\ Apache Tomcat 7.0.34 \\ lib目录中。

Sorry for responding late, i have limited time online 抱歉回复晚,我上网时间有限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM