javadoc未附加到依赖项时如何将javadocs引用到Maven的eclipse插件中的依赖项

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

How to reference javadocs to dependencies in Maven's eclipse plugin when javadoc not attached to dependency

javaeclipsemaven-2

提问by John in MD

I use Eclipse, Maven, and Java in my development. I use Maven to download dependencies (jar files and javadoc when available) and Maven's eclipse plug-in to generate the .project and .classpath files for Eclipse. When the dependency downloaded does not have attached javadoc I manually add a link for the javadoc in the .classpath file so that I can see the javadoc for the dependency in Eclipse. Then when I run Maven's eclipse plugin to regenerate the .classpath file it of course wipes out that change.

我在开发中使用 Eclipse、Maven 和 Java。我使用 Maven 下载依赖项(可用的 jar 文件和 javadoc)和 Maven 的 eclipse 插件来为 Eclipse 生成 .project 和 .classpath 文件。当下载的依赖项没有附加 javadoc 时,我会在 .classpath 文件中手动添加 javadoc 的链接,以便我可以在 Eclipse 中查看依赖项的 javadoc。然后,当我运行 Maven 的 eclipse 插件来重新生成 .classpath 文件时,它当然会消除该更改。

Is there a way to configure Maven's eclipse plug-in to automatically add classpath attributes for javadoc when running Maven's eclipse plug-in?

有没有办法配置Maven的eclipse插件在运行Maven的eclipse插件时自动为javadoc添加classpath属性?

I'm only interested in answers where the javadoc and/or sources are not provided for the dependency in the maven repository, which is the case most often for me. Using downloadSources and/or downloadJavadocs properties won't help this problem.

我只对没有为 maven 存储库中的依赖项提供 javadoc 和/或源的答案感兴趣,这对我来说是最常见的情况。使用 downloadSources 和/或 downloadJavadocs 属性不会解决这个问题。

采纳答案by Mike Deck

You might consider just avoiding this problem completely by installing the javadoc jar into your local repository manually using the install-file goaland passing in the -Dclassifier=javadoc option. Once you do that the .classpath that mvn generates should be correct.

您可以考虑通过使用install-file 目标手动将 javadoc jar 安装到本地存储库并传入 -Dclassifier=javadoc 选项来完全避免此问题。一旦你这样做了 mvn 生成的 .classpath 应该是正确的。

If you use a remote repo as a proxy to central you could also deploy the javadocs to that repo and then everyone else who uses that proxy will now get the javadocs automatically as well.

如果您使用远程存储库作为 Central 的代理,您还可以将 javadoc 部署到该存储库,然后使用该代理的其他所有人现在也将自动获取 javadoc。

回答by matt b

Would having the sources for the dependency help? You can tell the eclipse plugin to download those (and refer to them in the .classpath) with -DdownloadSources=true

拥有依赖的来源会有所帮助吗?您可以告诉 eclipse 插件下载这些(并在 .classpath 中引用它们)-DdownloadSources=true

回答by ddimitrov

From the Maven Eclipse Plugin FAQ

来自 Maven Eclipse 插件常见问题解答

The following example shows how to do this in the command-line:

mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true 

or in your pom.xml:

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

以下示例显示了如何在命令行中执行此操作:

mvn eclipse:eclipse -DdownloadSources=true  -DdownloadJavadocs=true 

或者在你的 pom.xml 中:

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

回答by luckyphil

I'm running STS 2.8.1 which is basically eclipse + spring tools; In an existing maven project, I right clicked on the project -> maven -> Download Sources and Download JavaDocs

我正在运行 STS 2.8.1,它基本上是 eclipse + spring 工具;在现有的 maven 项目中,我右键单击该项目 -> maven -> Download Sources and Download JavaDocs

回答by Philippe

As mentioned in How to download sources and javadoc artifacts with Maven Eclipse plugin from other repository?, you can do this:

如何使用 Maven Eclipse 插件从其他存储库下载源代码和 javadoc 工件中所述?, 你可以这样做:

In Eclipse go to Windows-> Preferences-> Maven. Check the box that says "Download Artifact Javadoc." That has worked well for me.

在 Eclipse 中,转到 Windows-> 首选项-> Maven。选中“下载 Artifact Javadoc”框。这对我来说效果很好。

Maven Preferences

Maven 首选项

回答by KulDeep

Generally Javadocs are not primarily used as dependency . Because these are neither required at compile nor runtime. It's just to help the developer while developing or debugging.

通常 Javadocs 不主要用作依赖项。因为这些在编译和运行时都不是必需的。它只是在开发或调试时帮助开发人员。

Assuming using the java IDE Eclipse we can use the java docs as referenced. Following are the approaches we can associate the javadocs/sources with the respective jars.

假设使用 java IDE Eclipse,我们可以使用引用的 java 文档。以下是我们可以将 javadocs/sources 与相应的 jars 相关联的方法。

1. If it's non-maven project :

1.如果是非maven项目:

Download the javadocs jar or zipped file, whatever available and placed it in some directory. Right click on the application project in the IDE Eclipse, click Properties and choose Java Build Path then select tab Libraries under the Java Build Path. Now expand the jar you want to link with java docs/source. Select the Javadoc location link and click on Edit button, a new window appears where we need to choose the javadocs jar path. Click OK and we have linked the javadoc/source with the respective jars.

下载 javadocs jar 或压缩文件(无论可用)并将其放置在某个目录中。右键单击IDE Eclipse 中的应用程序项目,单击Properties 并选择Java Build Path,然后选择Java Build Path 下的选项卡Libraries。现在展开要与 java docs/source 链接的 jar。选择 Javadoc 位置链接并单击 Edit 按钮,将出现一个新窗口,我们需要在其中选择 javadocs jar 路径。单击确定,我们已将 javadoc/source 与相应的 jar 链接。

enter image description here

在此处输入图片说明

2. If it's a maven project

2.如果是maven项目

If we are using the Maven project then go to jar files under the Maven dependency under the project in Project Explorer view as shown below. Now right click on the jar file you want to add the Javadoc/source, ? choose Maven then click on Javadoc or Source you want to link with the project. Now IDE will automatically download the required javadoc/source and will link it with the respective jar in the project.

如果我们使用的是 Maven 项目,则在 Project Explorer 视图中转到该项目下的 Maven 依赖项下的 jar 文件,如下所示。现在右键单击要添加 Javadoc/source 的 jar 文件,? 选择 Maven,然后单击要与项目链接的 Javadoc 或 Source。现在 IDE 将自动下载所需的 javadoc/source 并将其与项目中的相应 jar 链接。

enter image description here

在此处输入图片说明

You can verify this by right click on the project in the IDE and click on Java Build Path and select the Libraries tab under the Java Build Path and then expand the desired jar, here when you click the Edit button you will see the linked path of the Javadoc/Source with the respective jar as shown below in the image.

您可以通过在 IDE 中右键单击项目并单击 Java Build Path 并选择 Java Build Path 下的 Libraries 选项卡,然后展开所需的 jar 来验证这一点,当您单击 Edit 按钮时,您将看到链接的路径带有相应 jar 的 Javadoc/Source,如下图所示。

enter image description here

在此处输入图片说明

3. If it's Maven project and we are setting the default behavior:

3. 如果是 Maven 项目并且我们正在设置默认行为:

Eclipse will aquatically download the javadoc/source along with the main required jar at the starting. By default setting instruction to Maven to download the Javadoc/sources for all the jars linked in the project.

Eclipse 将在开始时水上下载 javadoc/source 以及主要所需的 jar。默认情况下,Maven 设置指令以下载项目中链接的所有 jar 的 Javadoc/源代码。

Click Windows – preferences – select Maven and click the checkbox Download Artifact Javadoc as shown below

点击Windows——首选项——选择Maven,点击复选框Download Artifact Javadoc,如下图

enter image description here

在此处输入图片说明

Now click on apply and save it and now when you create new Maven project , by default the Javadocs will get downloaded and linked with all the dependent jars in the project.
You can verify by right click on the project and Properties and under Java Build path can see the javadocs are linked with all the jars as shown below.

现在单击应用并保存它,现在当您创建新的 Maven 项目时,默认情况下 Javadoc 将被下载并与项目中的所有依赖 jar 链接。
您可以通过右键单击项目和属性进行验证,在 Java Build 路径下可以看到 javadocs 与所有 jars 链接,如下所示。

enter image description here

在此处输入图片说明

If your project is Maven project then It's always best to use 2nd approach because by using this approach the IDE and Maven, takes care of downloading the correct version of the Javadoc/source and linked it with the relative jar as well.

如果您的项目是 Maven 项目,那么最好使用第二种方法,因为通过使用这种方法,IDE 和 Maven 负责下载正确版本的 Javadoc/源并将其与相关 jar 链接。

Approach 3rd is bit costly because the javadoc/sources will be downloaded for-all the dependent jars, may be you are not interested for javadocs/sources for all the dependent jars.

方法 3 有点昂贵,因为 javadoc/sources 将下载所有依赖 jars,可能你对所有依赖 jars 的 javadocs/sources 不感兴趣。