我正在使用Eclipse IDE(3.6)开发一个用Java(1.6)编写的Web应用程序项目,并决定使用Jetty(8.0.4)作为Web服务器和servlet容器。 我正在使用 maven (2) 进行依赖和构建管理。 为了开始,我决定编写一个简单的测试应用程序,以确保我的工作是端到端的。 这工作正常,我能够启动服务器并创建一些简单的 servlet。 但是,maven 没有下载源代码和 Javadoc jar,因此当鼠标悬停在方法名称或类上时,找不到任何文档。 它只报告以下内容:
Open Declaration javax.servlet.http.HttpServletResponse注意:此元素既没有附加源代码,也没有附加Javadoc,因此找不到Javadoc。
我已经搜索了如何做到这一点,我能找到的只是Eclipse网站上的这个页面,描述了如何配置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 的任何指示?
尝试使用此 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>
这两种解决方案仅在将源代码和 javadoc 提供给要从中下载的存储库时才有效。
在您的情况下(和您的版本),它应该可以工作,因为您可以在 Jetty 存储库中找到源代码.jar。