编译 Servlet 库时 Javac 出错 [英] Javac erroring out when compiling Servlet libraries
问题描述
我正在使用 ubuntu,并且我已将路径设置为以下内容:
I am using ubuntu and I have set my paths to be the following:
JAVA_HOME=/usr/local/jdk1.6.0_24
export CLASSPATH=/usr/local/tomcat/lib
export JAVA_HOME
我认为这会将 servlet 库放在编译路径中,但我仍然收到如下编译错误:
I thought that would put the servlet libraries in the compile path, but I am still getting compile errors like this:
package javax.servlet does not exist
[javac] import javax.servlet.ServletException;
任何想法如何解决这个问题或我做错了什么?通用 Java 库似乎运行良好.
Any ideas how to fix this or what I am doing wrong? The general Java libraries seem to be working fine.
推荐答案
对于 jar 文件,仅指定包含 jar 文件的目录是行不通的.您有两个选择:
With jar files, simply specifying a directory containing jar files will not work. You have two options:
在 CLASSPATH 上单独指定每个 jar 文件:
Specify each jar file individually on the CLASSPATH:
export CLASSPATH=/usr/local/tomcat/lib/servlet-impl.jar:/path/to/another.jar
由于您使用的是 Java 6,您应该能够使用 通配符(包含目录中的所有 jar):
Since you're using Java 6, you should be able to use wildcards (to include all jars in a directory):
export CLASSPATH=/usr/local/tomcat/lib/*
这篇关于编译 Servlet 库时 Javac 出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!