我正在使用Eclipse IDE(3.6)开发用Java(1.6)编写的Web应用程序项目,并决定使用Jetty(8.0.4)作为Web服务器和servlet容器。我正在使用maven(2)进行依赖和构建管理。为了开始,我决定编写一个简单的测试应用程序,以确保我的工作端到端。这工作正常,我能够启动服务器并创建一些简单的servlet。但是,maven并没有下载源代码和Javadoc jar文件,因此当鼠标悬停在方法名称或类上时,没有找到任何文档。它只报告以下内容:
打开声明javax.servlet.http.HttpServletResponse 注意:此元素既没有附加源也没有附加Javadoc,因此找不到Javadoc。
我已经搜索了如何执行此操作,我在Eclipse网站上找到的所有内容都是this page,描述了如何配置maven以下载源模块。它表示源模块jar与二进制jar具有相同的名称,后缀为“-sources”。我为每个二进制模块添加了源模块依赖项到我的maven配置,如下所示:
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server-sources</artifactId>
<version>${jettyVersion}</version>
</dependency>
但是,maven找不到源模块依赖项:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Jetty Servlet Example 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server-sources/8.0.4.v20111024/jetty-server-sources-8.0.4.v20111024.pom
[WARNING] The POM for org.eclipse.jetty:jetty-server-sources:jar:8.0.4.v20111024 is missing, no dependency information available
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlet-sources/8.0.4.v20111024/jetty-servlet-sources-8.0.4.v20111024.pom
[WARNING] The POM for org.eclipse.jetty:jetty-servlet-sources:jar:8.0.4.v20111024 is missing, no dependency information available
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-util-sources/8.0.4.v20111024/jetty-util-sources-8.0.4.v20111024.pom
[WARNING] The POM for org.eclipse.jetty:jetty-util-sources:jar:8.0.4.v20111024 is missing, no dependency information available
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-server-sources/8.0.4.v20111024/jetty-server-sources-8.0.4.v20111024.jar
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlet-sources/8.0.4.v20111024/jetty-servlet-sources-8.0.4.v20111024.jar
Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-util-sources/8.0.4.v20111024/jetty-util-sources-8.0.4.v20111024.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.098s
[INFO] Finished at: Sun Apr 15 15:42:59 PDT 2012
[INFO] Final Memory: 5M/180M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project hello-world: Could not resolve dependencies for project org.example:hello-world:jar:0.1-SNAPSHOT: The following artifacts could not be resolved: org.eclipse.jetty:jetty-server-sources:jar:8.0.4.v20111024, org.eclipse.jetty:jetty-servlet-sources:jar:8.0.4.v20111024, org.eclipse.jetty:jetty-util-sources:jar:8.0.4.v20111024: Could not find artifact org.eclipse.jetty:jetty-server-sources:jar:8.0.4.v20111024 in central (http://repo1.maven.org/maven2) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
有关如何配置maven以下载Jetty源和javadocs的任何指示?
答案 0 :(得分:3)
尝试使用此Maven命令重新创建Eclipse项目:
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
另一个选择是更新你的pom.xml:
<plugin>
<artifactId>org.eclipse.jetty</artifactId>
<version>${jettyVersion}</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
只有将source和javadoc提供给您正在下载的repo时,这两种解决方案才有效。
在你的情况下(以及你的版本),它应该可以工作,因为你可以在Jetty存储库中找到the sources.jar。