I am trying to compile a simple class that imports some servlet libraries. Since I did not add the tomcat directory to the classpath, what is the best practice for letting the system know where to look for the servlet libraries that are in the tomcat / lib folder?
Currently, the system simply gives the following errors:
ackage javax.servlet does not exist [javac] import javax.servlet.ServletException;
If you want to use only the provided java tools, you will need to look at the JavaDocs for the javac tool and manually add the necessary pieces to the class path.
, " ", Maven, Ant IDE, .
ecplise, application server runtime library , add jar java-.
application server runtime library
add jar
, , javac? classpath classpath Java. - .
javac
, -cp -classpath javac. , () JAR .
-cp
-classpath
javac -cp .:/path/to/Tomcat/lib/servlet-api.jar com/example/MyServlet.java
. . Windows , , .
.
eclipse.
,
- → → → ALT + R → , → → .
: Eclipse Helios.
eclipse. Apache Tomcat eclipse
. Java IDE .
Maven , "" . , :
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet</artifactId> <version>2.1</version> <scope>provided</scope> </dependency>