Java 导入错误
我正在尝试导入 org.apache.commons.fileupload.*
但我被告知它不存在。
我正在下载这个 JAR: http://commons.apache.org/fileupload/
并将其放在类路径。那么我在这里做错了什么?
I'm trying to import org.apache.commons.fileupload.*
but I am being told that it does not exist.
I am downloading this JAR: http://commons.apache.org/fileupload/
And placing it on the classpath. So what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您很可能正在考虑
%CLASSPATH%
环境变量。你不应该这样做。 JAR 文件必须位于动态 Web 应用程序项目的/WEB-INF/lib
文件夹中。默认情况下,该文件夹由 web 应用程序的类路径覆盖。每当您将 JAR 文件放入该文件夹中时,一个不错的 IDE(Eclipse、Netbeans 等)都会自动将其添加到构建路径。当您在命令控制台中使用普通
javac.exe
进行编译时,您必须在-cp
参数中指定它。更新:
假设您使用的是 Windows 并且位于源根文件夹中,
javac.exe
的外观应如下所示:注意:通配符仅适用于 JDK 1.6 或更高版本。否则,您必须单独指定所有库。
Most likely you're thinking of
%CLASSPATH%
environment variable. You shouldn't do that. The JAR file has to go in/WEB-INF/lib
folder of the dynamic web application project. That folder is by default covered by the webapp's classpath. A bit decent IDE (Eclipse, Netbeans, etc) will automagically add it to the Build Path whenever you drop a JAR file in that folder.When you're compiling using plain vanilla
javac.exe
in command console, then you have to specify it in the-cp
argument.Update:
Assuming that you're using Windows and are sitting in source root folder, here's how
javac.exe
should look like:Note: the wildcard only works on JDK 1.6 or newer. Otherwise you've to specify all libraries separately.
该 jar 是否在您的类路径中?另请查看此讨论关于通配符导入的缺点。
Is the jar in your classpath? Also check out this discussion on the downsides of wildcard imports.
你在罐子里看到你的班级了吗?要查明您的类是否存在于 jar 中,请执行以下操作:
要查明您的类是否存在于多个 jar 中的任何一个中,您可以执行以下操作:
Do you see your class in the jar? To find out if your class exists in a jar, do the following:
To find out if your class exists in any of a number of jars, you can do this:
由于您正在编写 servlet,因此您可能已经创建了一个 Web 项目。将您的 fileupload jar 放入
WEB-INF/lib
文件夹中,然后在 IDE 中刷新您的项目,以便自动将其放置在您的项目构建路径中。编辑看到您使用的是命令行,请确保提供
CLASSPATH
的完整 jar 文件路径(包括 jar 名称及其扩展名,以分号分隔) 。Since you're writing a servlet, you've probably created a web project. Place your fileupload jar inside the
WEB-INF/lib
folder and let refresh your project in the IDE to be placed automatically in your project build path.Edit Seeing you're using command-line, make sure that you provide the full jar file path to the
CLASSPATH
(including the jar name and its extension, separated by semicolon).