为 Maven 管理的依赖项获取附加到 Eclipse 的源 jar 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/310720/
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 18:31:28  来源:igfitidea点击:

Get source jar files attached to Eclipse for Maven-managed dependencies

eclipsemaven-2javadoc

提问by Thilo

I am using Maven (and the Maven Eclipse Integration) to manage the dependencies for my Java projects in Eclipse. The automatic download feature for JAR files from the Maven repositories is a real time saver. Unfortunately, it does not include API documentation and source code.

我正在使用 Maven(和 Maven Eclipse 集成)来管理 Eclipse 中我的 Java 项目的依赖项。从 Maven 存储库自动下载 JAR 文件的功能可以实时节省时间。不幸的是,它不包括 API 文档和源代码。

How can I set up Maven to automatically also get the source and javadoc attachments and register them properly with Eclipse?

如何设置 Maven 以自动获取源和 javadoc 附件并在 Eclipse 中正确注册它们?

回答by mrembisz

I am sure m2eclipse Maven plugin for Eclipse - the other way around - can do that. You can configure it to download both the source files and javadoc automatically for you.

我确信用于 Eclipse 的 m2eclipse Maven 插件 - 反过来 - 可以做到这一点。您可以将其配置为自动为您下载源文件和 javadoc。

This is achieved by going into Window > Preferences > Maven and checking the "Download Artifact Sources" and "Download Artifact JavaDoc" options.

这是通过进入 Window > Preferences > Maven 并检查“Download Artifact Sources”和“Download Artifact JavaDoc”选项来实现的。

Screenshot of Maven Preferences

Maven 首选项的屏幕截图

回答by Stephen Denne

mvn eclipse:eclipse -DdownloadSources=true

or

或者

mvn eclipse:eclipse -DdownloadJavadocs=true

or you can add both flags, as Spencer K points out.

或者您可以添加两个标志,正如 Spencer K 指出的那样。

Additionally, the =trueportion is not required, so you can use

此外,该=true部分不是必需的,因此您可以使用

mvn eclipse:eclipse -DdownloadSources -DdownloadJavadocs

回答by overthink

The other answers on this work, but if you want to avoid having to remember command line arguments, you can also just add to the downloadSources and downloadJavadocs config to the maven-eclipse-plugin section of your pom.xml:

关于这项工作的其他答案,但如果您想避免记住命令行参数,您还可以将 downloadSources 和 downloadJavadocs 配置添加到 pom.xml 的 maven-eclipse-plugin 部分:

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    ... other stuff ...
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

回答by Duncan Jones

I prefer not to put source/Javadoc download settings into the project pom.xmlfile as I feel these are user preferences, not project properties. Instead, I place them in a profile in my settings.xmlfile:

我不想将源代码/Javadoc 下载设置放入项目pom.xml文件中,因为我觉得这些是用户首选项,而不是项目属性。相反,我将它们放在我的settings.xml文件中的配置文件中:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <profiles>
    <profile>
      <id>sources-and-javadocs</id>
      <properties>
        <downloadSources>true</downloadSources>
        <downloadJavadocs>true</downloadJavadocs>
      </properties>
    </profile>
  </profiles>

  <activeProfiles>
    <activeProfile>sources-and-javadocs</activeProfile>
  </activeProfiles>
</settings>

回答by sumeet

Right click on project -> maven -> download sources

右键单击项目 -> maven -> 下载源

回答by Hardy

If the source jars are in the local repository and you are using Eclipses maven support the sources are getting automatically attached. You can run mvn dependency:sourcesto download all source jars for a given project. Not sure how to do the same with the documentation though.

如果源 jar 位于本地存储库中,并且您使用的是 Eclipse Maven 支持,则源会自动附加。您可以运行mvn dependency:sources以下载给定项目的所有源 jar。不知道如何对文档做同样的事情。

回答by surajz

If you are using meclipse do

如果你使用 meclipse 做

window --> maven --> Download Artifact Sources (select check)

window --> maven --> Download Artifact Sources (select check)

(If you still get attach source window, then click on attach file button and close the attach source window. The next time you try to see the source it will open the correct source)

(如果您仍然获得附加源窗口,则单击附加文件按钮并关闭附加源窗口。下次您尝试查看源时,它将打开正确的源)

Surajz

苏拉兹

回答by andrel

There is also a similiar questionthat answers this and includes example pom settings.

还有一个类似的问题可以回答这个问题并包括示例 pom 设置。

回答by om39a

I tried windows->pref..->Maven But it was not working out. Hence I created a new class path with command mvn eclipse:eclipse -DdownloadSources=true and refreshed the workspace once. voila.. Sources were attached.

我试过 windows->pref..->Maven 但它没有奏效。因此,我使用命令 mvn eclipse:eclipse -DdownloadSources=true 创建了一个新的类路径并刷新了工作区一次。瞧.. 来源已附上。

Source jar's entry is available in class path. Hence new build solved the problem...

源 jar 的条目在类路径中可用。因此,新版本解决了这个问题......

回答by bnguyen82

Changing pom for maven-eclipse-plugin to include source/javadoc just apply for new dependencies being added to pom. If we need to apply for existing dependencies, we must run mvn dependency:sources. I checked this.

更改 maven-eclipse-plugin 的 pom 以包含 source/javadoc 只需申请添加到 pom 的新依赖项。如果我们需要申请现有的依赖,我们必须运行 mvn dependency:sources。我检查了这个。