java servlet error on compile
So I was compiling a package using javac -Xlint from开发者_高级运维 the command prompt and then it was complaining:
package javax.servlet does not exist
I know that this refers to the servlet jar from the tomcat and I acquired the jar...my question is how do I get javac to know the path to this jar so that it wont spill out this error
javac.exe has a -classpath option. Add all paths and JARs there.
If you use an IDE, you'll need to figure out how to set up its build CLASSPATH.
Or learn Ant.
If you're developing a servlet, you'll have to deploy it in a WAR file. Fortunately the servlet.jar for Tomcat is in its /lib directory, so the Tomcat class loader will find it.
Your WAR file's WEB-INF/lib JARs are automatically in the CLASSPATH at runtime; so are all the .class files Tomcat finds in your WEB-INF/classes.
Try this link on how to set the classpath. You need to add the servlet.jar from tomcat to the classpath to prevent the error. The two ways are: -
- add it as an environment variable
- add it via the -classpath option in javac
精彩评论