Java compilation gives errors in servlet libraries

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;
0
source share
5 answers

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

+2

ecplise, application server runtime library , add jar java-.

+1

, , javac? classpath classpath Java. - .

, -cp -classpath javac. , () JAR .

javac -cp .:/path/to/Tomcat/lib/servlet-api.jar com/example/MyServlet.java

. . Windows , , .

+1

eclipse.

,

- → → → ALT + R → , → → .

: Eclipse Helios.

eclipse. Apache Tomcat eclipse

+1

. Java IDE .

Maven , "" . , :

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet</artifactId>
    <version>2.1</version>
    <scope>provided</scope>
</dependency>
0

All Articles