Java 包不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2455316/
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
Package does not exist
提问by Derk
I get an "Build failed" error with error output when I try to build my project in Eclipse:
当我尝试在 Eclipse 中构建我的项目时,我收到一个带有错误输出的“构建失败”错误:
[javac] ......\src\example\servlet\ScrapingServlet.java:10: package org.apache.http.client does not exist [javac] import org.apache.http.client.HttpClient;
[javac] ......\src\example\servlet\ScrapingServlet.java:10: package org.apache.http.client 不存在 [javac] import org.apache.http.client.HttpClient;
But the Eclipse editor does not give any error. I added the jars to the project with Project > properties > add external JARS... and all the JARS are showed in the project explorer. What am I doing wrong?
但是 Eclipse 编辑器没有给出任何错误。我使用 Project > properties > add external JARS... 将 jar 添加到项目中,并且所有 JARS 都显示在项目资源管理器中。我究竟做错了什么?
回答by Teja Kantamneni
Check whether you have added commons-httpclient.jar
or not.
检查您是否已添加commons-httpclient.jar
。
回答by Amber Shah
If you have just added the jars, sometimes you need to do a Clean and then build for it to take effect.
如果你刚刚添加了 jars,有时你需要做一次 Clean 然后构建它才能生效。
回答by Derk
Solved my problem. I had to add the filenames of the JARS to the build.xml file.
解决了我的问题。我必须将 JARS 的文件名添加到 build.xml 文件中。
回答by nicolas_eo
Try to added the jars to be copied in the build.xml, like this:
尝试在 build.xml 中添加要复制的 jars,如下所示:
<!-- copy JavaMail support jars build directory -->
<mkdir dir="${basedir}/jlib/javamail"/> <!-- make sure 'from' dir exists to avoid warnings -->
<copy todir="${build.lib}" failonerror="false" verbose="false">
<!-- ok if this file does not exist -->
<fileset dir="${basedir}/jlib/javamail">
<include name="activation.jar"/> <!-- not needed for JDK 6+ -->
<include name="mail.jar"/>
</fileset>
</copy>
this works for me ;)
这对我有用;)
回答by Joshua Pinter
I ran into a similar error in Android Studio.
我在Android Studio 中遇到了类似的错误。
I was added a module dependency of a libs/httpcomponents
directory I created that contained a number of jar
files, including commons-httpclient.jar
but that wasn't working for some reason.
我添加了一个libs/httpcomponents
我创建的目录的模块依赖项,其中包含许多jar
文件,包括commons-httpclient.jar
但由于某种原因不起作用。
Once I moved commons-httpclient.jar
to just the libs/
directory and updated the module dependency by adding that file explicitly, the build worked fine.
一旦我移动 commons-httpclient.jar
到libs/
目录并通过显式添加该文件更新模块依赖项,构建工作正常。
Weird science.
奇怪的科学。