简体   繁体   中英

Error compiling servlet: file not found

I'm trying to compile a servlet called BeerSelect.java and I'm getting this error:

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

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. (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:

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:

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"; -d classes \\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). I refined the command to look like this:

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

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.

Sorry for responding late, i have limited time online

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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