导入 org.apache.commons 无法在 eclipse juno 中解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14609722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:32:07  来源:igfitidea点击:

The import org.apache.commons cannot be resolved in eclipse juno

eclipseservletsapache-commons-fileupload

提问by

I having the problem while compiling the my project in eclipse. It was shoving the error The import org.apache.commons cannot be resolved.

在 Eclipse 中编译我的项目时遇到问题。这是推错误导入 org.apache.commons 无法解析

enter image description here

在此处输入图片说明

Please anyone tell me what does this error tells. and how to solve it.

请任何人告诉我这个错误说明了什么。以及如何解决。

采纳答案by BalusC

The mentioned package/classes are not present in the compiletime classpath. Basically, Java has no idea what you're talking about when you say to import this and that. It can't find them in the classpath.

提到的包/类不存在于编译时类路径中。基本上,当你说要导入这个和那个时,Java 不知道你在说什么。它在类路径中找不到它们。

It's part of Apache Commons FileUpload. Just download the JAR and drop it in /WEB-INF/libfolder of the webapp project and this error should disappear. Don't forget to do the same for Apache Commons IO, that's where FileUpload depends on, otherwise you will get the same problem during runtime.

它是Apache Commons FileUpload的一部分。只需下载 JAR 并将其放入/WEB-INF/libwebapp 项目的文件夹中,此错误就会消失。不要忘记对Apache Commons IO做同样的事情,这是 FileUpload 所依赖的地方,否则你会在运行时遇到同样的问题。



Unrelatedto the concrete problem, I see that you're using Tomcat 7, which is a Servlet 3.0 compatible container. Do you know that you can just use the new request.getPart()method to obtain the uploaded file without the need for the whole Commons FileUpload stuff? Just add @MultipartConfigannotation to the servlet class so that you can use it. See also How to upload files to server using JSP/Servlet?

具体问题无关,我看到您使用的是 Tomcat 7,它是一个 Servlet 3.0 兼容容器。你知道你可以使用新的request.getPart()方法来获取上传的文件而不需要整个 Commons FileUpload 的东西吗?只需@MultipartConfig向 servlet 类添加注释,以便您可以使用它。另请参阅如何使用 JSP/Servlet 将文件上传到服务器?

回答by chenlian

If you got a Apache Mavenproject, it's easy to use this package in your project. Just specify it in your pom.xml:

如果你有一个Apache Maven项目,在你的项目中使用这个包很容易。只需在您的pom.xml

<project>
...

    <properties>
        <version.commons-io>2.4</version.commons-io>
    </properties>

    <dependencies>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>${version.commons-io}</version>
        </dependency>
    </dependencies>

...
</project>

回答by Olivia Liao

You could just add one needed external jar file to the project. Go to your project-->java build path-->libraries, add external JARS.Then add your downloaded file from the formal website. My default name is commons-codec-1.10.jar

您可以只向项目添加一个需要的外部 jar 文件。进入你的项目-->java build path-->libraries,添加外部JARS。然后添加你从正式网站下载的文件。我的默认名称是 commons-codec-1.10.jar

回答by Deepak

expand "Java Resources" and then 'Libraries' (in eclipse project). make sure that "Apache Tomcat" present.

展开“Java 资源”,然后展开“库”(在 eclipse 项目中)。确保存在“Apache Tomcat”。

if not follow- right click on project -> "Build Path" -> "Java Build Path" -> "Add Library" -> select "Server Runtime" -> next -> select "Apache Tomcat -> click finish

如果没有跟随-右键单击项目->“构建路径”->“Java构建路径”->“添加库”->选择“服务器运行时”->下一步->选择“Apache Tomcat->点击完成

回答by yTze

Look for "poi-3.17.jar"!!!

寻找“poi-3.17.jar”!!!

  1. Download from "https://poi.apache.org/download.html".
  2. Click the one Binary Distribution -> poi-bin-3.17-20170915.tar.gz
  3. Unzip the file download and look for this "poi-3.17.jar".
  1. 从“ https://poi.apache.org/download.html”下载。
  2. 单击一个 Binary Distribution -> poi-bin-3.17-20170915.tar.gz
  3. 解压缩文件下载并查找此“poi-3.17.jar”。

Problem solved and errors disappeared.

问题解决,错误消失。