java Maven 依赖与 javadocs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17496996/
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
Maven dependency with javadocs
提问by AnthonyW
3 Questions:
3个问题:
Below are two maven dependencies for JUnit. I have been scouring the interwebs for hours and cannot seem to determine if the second one is Javadoc + code or only Javadoc. Do I need one or both? Further, what is the most effecient way to include Javadocs in a project for development yet not in the production build? (I would prefer not to manually download javadocs for every dependency on every machine.)
下面是 JUnit 的两个 Maven 依赖项。我已经在互联网上搜索了几个小时,似乎无法确定第二个是 Javadoc + 代码还是只有 Javadoc。我需要一个还是两个?此外,将 Javadocs 包含在开发项目中但不包含在生产构建中的最有效方法是什么?(我不想为每台机器上的每个依赖项手动下载 javadoc。)
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<classifier>javadoc</classifier>
</dependency>
EDIT: Questions:
编辑:问题:
- What is the difference between these dependencies?
- Do I need both of them to be able to use the dependency & have Javadoc on hand?
- What is best practice for including Javadocs for development?
- 这些依赖之间有什么区别?
- 我是否需要他们两个才能使用依赖项并手头有 Javadoc?
- 将 Javadocs 用于开发的最佳实践是什么?
采纳答案by John Ament
Generally speaking, your IDE will handle the resolution of javadoc for you in a maven project. This is assuming your IDE understands maven - e.g. netbeans, intellij or eclipse w/ m2e.
一般而言,您的 IDE 会在 Maven 项目中为您处理 javadoc 的解析。这是假设您的 IDE 理解 maven - 例如 netbeans、intellij 或 eclipse w/m2e。
The second artifact is only the javadocs. The first artifact is the code. There's almost never a good reason to include the javadoc artifact as a dependency.
第二个工件只是 javadoc。第一个工件是代码。几乎没有充分的理由将 javadoc 工件作为依赖项包含在内。
回答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 :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.
1. 如果它是非 maven 项目:下载 javadocs jar 或压缩文件,任何可用的并将其放置在某个目录中。右键单击IDE Eclipse 中的应用程序项目,单击Properties 并选择Java Build Path,然后选择Java Build Path 下的选项卡Libraries。现在展开要与 java docs/source 链接的 jar。选择 Javadoc 位置链接并单击 Edit 按钮,将出现一个新窗口,我们需要在其中选择 javadocs jar 路径。单击“确定”,我们已将 javadoc/source 与相应的 jar 链接。
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 链接。
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,如下图所示。
3. If it's Maven project and we are setting the default behaviour:
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,如下图
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 链接,如下所示。
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 forall the dependent jars, may be you are not interested for javadocs/sources for all the dependent jars.
方法 3 有点昂贵,因为将为所有依赖的 jar 下载 javadoc/源,可能您对所有依赖的 jar 的 javadoc/源不感兴趣。
回答by Alex
I stumbled upon this problem when I created a maven project in eclipse and neither javadoc nor source of my dependencies where attached to my project, and I wondered which dependency to add.
当我在 eclipse 中创建一个 maven 项目时,我偶然发现了这个问题,但 javadoc 和我的依赖项的源都没有附加到我的项目中,我想知道要添加哪个依赖项。
What helped me was adding
帮助我的是添加
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>
to my pom.xml. That way, you only have to use the first dependency, and maven/eclipse take care of downloading the second (which is, as pointed out in the other answer, only the javadoc).
到我的 pom.xml。这样,您只需要使用第一个依赖项,而 maven/eclipse 负责下载第二个(正如另一个答案中所指出的,只有 javadoc)。