Get source JARs from Maven repository - java

Does anyone have any idea if you can find source JARs on Maven repositories?

Maven Micro-Tip: Get sources and Javadocs
When you're using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There's an easy way to accomplish that goal.
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
The first command will attempt to download source code for each of the dependencies in your pom file.
The second command will attempt to download the Javadocs.
Maven is at the mercy of the library packagers here. So some of them won't have source code packaged and many of them won't have Javadocs.
In case you have a lot of dependencies it might also be a good idea to use
inclusions/exclusions to get specific artifacts, the following command
will for example only download the sources for the dependency with
a specific artifactId:
mvn dependency:sources -DincludeArtifactIds=guava
Source: http://tedwise.com/2010/01/27/maven-micro-tip-get-sources-and-javadocs/
Documentation: https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html

Configuring and running the maven-eclipse plugin, (for example from the command line mvn eclipse:eclipse )
<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>

If a project creates a jar of the project sources and deploys it to a maven repository, then you'll find it :)
Just FYI, sources artifacts are generally created by the maven-source-plugin. This plugin can bundle the main or test sources of a project into a jar archive and, as explained in Configuring Source Plugin:
(...) The generated jar file will be named by the value of the finalName plus "-sources" if it is the main sources. Otherwise, it would be finalName plus "-test-sources" if it is the test sources.
The additional text was given to describe an artifact ("-sources" or "-test-sources" here) is called a classifier.
To declare a dependency on an artifact that uses a classifier, simply add the <classifier> element. For example:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.7.ga</version>
<classifier>sources</classifier>
</dependency>
Note that you generally don't do this, most IDEs provide support to download sources (and/or JavaDoc) from the main artifact without declaring explicitly a dependency on them.
Finally, also note that some repository search engines allow searching for artifacts using the classifier (at least Nexus does with the advanced search). See this search for example.

The maven idea plugin for IntelliJ Idea allows you to specify whether or not sources and java doc should be resolved and downloaded
mvn idea:idea -DdownloadSources=true -DdownloadJavadocs=true

To download any artifact use
mvn dependency:get -Dartifact=groupId:artifactId:version:packaging:classifier
For Groovy sources this would be
mvn dependency:get -Dartifact=org.codehaus.groovy:groovy-all:2.4.6:jar:sources
For Groovy's javadoc you would use
mvn dependency:get -Dartifact=org.codehaus.groovy:groovy-all:2.4.6:jar:javadoc
This puts the given artifact into your local Maven repository, i.e. usually $HOME/.m2/repository.
dependency:sources just downloads the project dependencies' sources, not the plugins sources nor the sources of dependencies defined inside plugins.

To download some specific source or javadoc we need to include the GroupIds - Its a comma separated value as shown below
mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=sources
Note that the classifier are not comma separated, to download the javadoc we need to run the above command one more time with the classifier as javadoc
mvn dependency:sources -DincludeGroupIds=com.jcraft,org.testng -Dclassifier=javadoc

you can find info in this related question: Get source jar files attached to Eclipse for Maven-managed dependencies
if you use the eclipse maven plugin then use 'mvn eclipse:eclipse -DdownloadSources=true'

if you're using eclipse you could also open Preferences > Maven and select Download Artifact Sources, this would let the pom.xml intact and keep your sources or java docs (if selected) just for development right at your machine location ~/.m2

In Eclipse
Right click on the pom.xml
Select Run As -> Maven generate-sources
it will generate the source by default in .m2 folder
Pre-Requisite:
Maven should be configured with Eclipse.

In eclipse - click on the project then:
.

You can, if they are uploaded. Generally they are called "frameworkname-version-source(s)"

NetBeans, Context-Click
In NetBeans 8 with a Maven-driven project, merely context-click on the jar file list item of the dependency in which you are interested. Choose Download Sources. Wait a moment and NetBeans will automatically download and install the source code, if available.
Similarly you can choose Download Javadoc to get the doc locally installed. Then you can context-click some code in the editor and choose to see the JavaDoc.

Based on watching the Maven console in Eclipse (Kepler), sources will be automatically downloaded for a Maven dependency if you attempt to open a class from said Maven dependency in the editor for which you do not have the sources downloaded already. This is handy when you don't want to grab source for all of your dependencies, but you don't know which ones you want ahead of time (and you're using Eclipse).
I ended up using #GabrielRamierez's approach, but will employ #PascalThivent's approach going forward.

If you know the groupId and aritifactId,you can generate download url like this.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
http://central.maven.org/maven2/ch/qos/logback/logback-classic/
and you will get a page like this, chose the version you need,just enjoy it!

I have also used the eclipse plugin to get the project into the eclipse workspace.
Since I've worked on a different project I saw that it is possible to work with eclipse but without the maven-eclipse-plugin. That makes it easier to use with different environments and enables the easy use of maven over eclipse. And that without changing the pom.xml-file.
So, I recommend the approach of Gabriel Ramirez.

Maven repositories do provide simple way to download sources jar.
I will explain it using a demonstration for "spring-boot-actuator-autoconfigure".
Go to maven repository -
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure
The page lists various versions. Click-on to desired one, let's say, 2.1.6.RELEASE - https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE
The page have link "View All" next to "Files". Click it -
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/
The page lists various files including the one for sources -
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/spring-boot-actuator-autoconfigure-2.1.6.RELEASE-sources.jar
Otherwise, you can always "git clone" the repo from github, if its there and get the specific code.
As explained by others, you can use "mvn dependency:sources" command the get and generate sources jar for the dependency you are using.
Note: Some dependencies will not have sources.jar, as those contains no source code but a pom file. e.g. spring-boot-starter-actuator.
As in this case:
Starter POMs are a set of convenient dependency descriptors that you can include in your application. You get a one-stop-shop for all the Spring and related technology that you need, without having to hunt through sample code and copy paste loads of dependency descriptors.
Reference: Intro to Spring Boot Starters

In IntelliJ IDEA you can download artifact sources automatically while importing by switching on Automatically download Sources option:
Settings → Build, Execution, Deployment → Build Tools → Maven → Importing

If you want find the source jar file for any of the artifact manually, go to maven repository location for the particular artifact and in Files click on 'view All'. You can find source jar file.

For debugging you can also use a "Java Decompiler" such as: JAD and decompile source on the fly (although the generated source is never the same as the original). Then install JAD as a plugin in Eclipse or your favorite IDE.

If you're using Eclipse, I would recommend downloading both the source and the Javadocs of third-party libraries.
Right click on project and download both as per the screenshot below.
Downloading Javadocs means that typically you can get contextual help for methods from third-party libraries, with useful description of parameters, etc. This is essential if you don't know the library well. In some cases I have found that Javadocs are available when the source isn't.

Related

Using third-party libraries in Eclipse RCP Tycho app

I've created a boiler-plate project following vogella's extensive Tycho tutorial.
Facts:
There's no feature, and there's no plugin. The only plugin is the RCP app, which is also the entry-point.
Problem:
I have no idea in which pom.xml do I include the 3rd party dependencies.
I cannot include them in the RCP project, because the packaging of that pom is eclipse-plugin, and not jar. From what I've noticed, if I change the packaging to jar, then the "Maven Dependencies" library is added automatically. If I change back to eclipse-plugin, they get removed.
Questions:
Where do I add the dependencies? There's no pom with jar packaging in my project.
Should I create a separate project with the necessary JARs? How do I include that dependency to my entire project?
Is it really that much of a good practice to create a separate plugin and a feature for this RCP app?
Related solutions:
"Update projects" doesn't work, and neither do the n other solutions in the other SO questions.
There's also this question and that question, but I don't fully get the answers
I think that you have a fundamental misunderstanding.
Maven: Maven determines all of the project dependencies via the pom.xml and resolves transitive dependencies automatically (assuming that all of the pom files and artifacts exist in repositories that you've configured and correctly declare their dependencies).
Tycho: The problem is that Eclipse already has its own project model based on product files, feature.xml files, and plug-in MANIFEST.MF files. Tycho leverages the Maven machinery for Eclipse, but the idea is that the pom.xml files just configure the Maven plug-ins and declare the packaging type. That provides an entry point for Maven, but then Tycho takes over. While Maven would normally build the dependency chain from information in the pom.xml files, Tycho is building the dependency change from information in the product, feature, and MANIFEST.MF files. You don't put any dependencies in the pom.xml files. Tycho also uses Eclipse p2 repositories (instead of normal Maven repositories) for finding dependent plug-ins that are not found in the local modules or target platform.
That's actually a benefit for many Eclipse developers since they've already set up everything properly in their Eclipse plug-ins, features, and products. They do not want to have to repeat all of the dependencies in the pom.xml.
Using Libraries in Eclipse plug-ins: In Eclipse, if you want to use a library that is not already packaged as an Eclipse plug-in, you have a few options. Your plug-in can include a set of JARs in a libs folder and then include that libs folder in the plug-in and runtime classpath (see the build.properties file). Another option is to create your own "library plug-in" that repackages a JAR library as an Eclipse plug-in. See also https://wiki.eclipse.org/FAQ_What_is_the_classpath_of_a_plug-in%3F. That's the answer that you're getting above.
The problem is that if you're trying to include a complex library with multiple JARs that is normally distributed and included in a standard Java project via Maven. We hit this problem with the Jersey JAX-RS implementation in my project. There's no p2 repository that includes all of the pieces of the libraries as plug-ins with correct dependency information.
Easy Solution: If you need a common library, check the Orbit project first to see whether the libraries have already been packaged as Eclipse plug-ins, http://www.eclipse.org/orbit/. In that case, you can download them and include them in your target platform, or you can pull them in dynamically at (Tycho) build time from their p2 repository. Your plug-ins would just include those plug-ins as dependencies (in the their MANIFEST.MF files).
Workaround / Solution: In our case, Jersey JAX-RS was not available as an Eclipse plug-in, and it had a bunch of transitive dependencies. The workaround was to create an Eclipse "library plug-in" like I mentioned above with two pom files. We initially created a skeleton plug-in with an empty libs folder. One pom file is just a standard Maven pom file with <packaging>jar</packaging> that declares the top-level dependencies required to pull in the Jersey JAX-RS implementation and all of its dependencies. The dependencies are declared with <scope>compile</scope>. We use the maven-dependency-plugin to copy all of those dependencies into the project's libs folder.
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>libs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
We actually ended up running Maven with that pom by hand from time to time to update the libs, and then we just checked the plug-in with all of its dependent JARs into source control. Checking the build later, I see that we actually populate the libs folder on-the-fly with Maven with a separate build task just before we start the Maven/Tycho part of the build. Of course, plug-in's MANIFEST-MF file's Bundle-ClassPath and Export-Package entries are coming straight from source control. We have to check those from time to time to ensure that they match the libraries and packages that we're getting from Maven. (That doesn't tend to change much unless we bump major library versions or add a new dependency at the Maven level.) The plug-in's build.properties has the libs/ folder as part of bin.includes.
In the development environment, after we first check out the code, we just run mvn (with an External Tools launch config that's also checked in with the project) on the project's "copy dependencies" pom file. That populates the libs folder with all of the JAX-RS libraries and dependencies. We only have to run it again when we update something about the dependencies or when we're jumping between branches that have different versions of the JAX-RS dependencies. We set .gitignore to ensure that we don't commit the libs to Git.
The other pom for this project is set up like a normal Tycho pom file with <packaging>eclipse-plugin</packaging>. During our automated build, we run one step early in the build process (just after check out) that calls mvn with the jar pom to populate the libs. Then we proceed with the main Maven/Tycho build using the eclipse-plugin pom. The eclipse-plugin pom has no dependency information (as I said above). It's just providing Tycho a way to recognize the Eclipse plug-in and build it based on its MANIFEST.MF and build.properties files. But the built plug-in includes and exposes all of those libs that were populated by the mvn call to the jar pom step.
So, it's a bit of a mess, but that's the best solution we found a couple of years ago when we hit this problem. I'm not sure whether Tycho is doing any work to permit some sort of hybrid Maven/Tycho build that could do this automatically as part of the build. I guess I should ask the developers. :)
Your questions:
Where do I add the dependencies? There's no pom with jar packaging in my project. Answer: The workaround above lets you do it with one project. You just have two pom files, like pom_deps.xml and pom.xml. You just have to invoke the pom_deps.xml separately to populate the libs folder (in the dev environment and with your automated builds).
Should I create a separate project with the necessary JARs? How do I include that dependency to my entire project? Answer: the workaround that I described above lets you do it with a single project. Another way to do it is to create a separate JAR project, but I don't think that your Eclipse RCP app can really include a <packaging>jar</packaging> module in a useful way. The only way I've found to do it is to use a similar workaround. You build the JAR module first, install it into the maven repository, and then have one of your plug-in projects bundle the JAR in its libs folder. (If you really want to do it that way, ask. We have a case where we have to do that, too, and I can provide the steps we do in development and the build to make it work. I think the single project workaround that I provided above makes more sense for your case.)
Is it really that much of a good practice to create a separate plugin and a feature for this RCP app? Answer: that's really a separate question. If you have a feature with multiple plug-ins, you have the same problem. Tycho can handle the product/feature/plug-ins, but it cannot jump across into Maven-based dependency resolution. You'll end up having to use the same workarounds
Summary: The fundamental issue is that Eclipse plug-ins can't "see" a bare JAR library. The plug-in needs to have the library included in its local libs folder (with a matching Bundle-ClassPath entry in MANIFEST.MF), or it needs to depend on some other plug-in that exports the appropriate packages. Tycho just resolves dependencies via Eclipse plug-ins, and it cannot leverage normal Maven dependency resolution directly to pull in a bunch of JARs. If all of your dependencies are already plug-ins, you're fine. If not, you may have to use the workaround above to package a set of libraries for your plug-ins to use.
Just adding the plugin to pom dependencies and including the entry <pomDependencies>consider</pomDependencies> in the configuration of target-platform-configuration makes it work.
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<!-- The configuration to make tycho consider the maven dependencies -->
<pomDependencies>consider</pomDependencies>
<!-- other configurations -->
</configuartion>
</plugin>
<!-- other plugins-->
</plugins>
<dependencies>
<!-- An example third-party bundle (plugin) present in maven repository-->
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
Reference link here.

Maven dependency with javadocs

3 Questions:
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.)
<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?
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.
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.
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.
2. If it’s a maven project
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.
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.
3. If it’s Maven project and we are setting the default behaviour:
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.
Click Windows – preferences – select Maven and click the checkbox Download Artifact Javadoc as shown below
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.
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.
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.
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.
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.
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.
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).

Shortest way to see Maven's supremacy in Eclipse?

Suppose I have created an empty Maven project in Eclipse. What is the shortest way to observe Maven's ability of automatic jar downloading and dependency checking? For example, I need to use Swing or log4j library. How can I add them without thinking where to download?
Add a dependency, for example, Log4J 1.2.16; it will be downloaded automatically, along with its dependencies. Then check in your home directory's .m2/repository directory.
(You'll find mvnrepository.com helpful; bookmark it!)
Add this at the end of your pom :
<repository>
<id>jboss-nexus</id>
<url>https://repository.jboss.org/nexus/</url>
</repository>
Then go to this location and look for the artifacts you need. Once you've found them add them to your project dependencies (the site even shows the complete dependency).
Run mvn install and then mvn eclipse:eclipse and voila, all done...

Applying Maven to a project

I've been asked to apply Maven to a project. After browsing a dozen sites it appears that it's quite vast and I'm not familiar as I'd like with similar tools like Ant. Why is it used/preferred and what does it offer over a standard Eclipse project? Also, how could it be added to an existing project?
Why is it used/preferred and what does
it offer over a standard Eclipse
project?
It is a build tool which can build your project without the need for an IDE like Eclipse. It can create a jar or war or other artifacts from the source, performing a bunch of steps like compilation, running unit tests, etc.
Where maven scores over ant is in managing third-party dependencies and in convention over configuration (which mean less lines of build script if you follow convention).
Also, how could it be added to an
existing project?
You start by creating a new maven project, following the step here.
Place it in the root folder of your project
If your source and resource files do not follow maven folder convention, update maven properties suitably referring to this documentation.
Run mvn package
It will fail if it needs any third party dependencies, which you can add as specified in the doc
With some trial and error, you should have your project running with maven, possibly, much quicker than if you were to set up the same with ant.
Others are already provided sufficient resources to read more about maven.
I suggest to start reading here:
http://www.sonatype.com/books/mvnref-book/reference/public-book.html
Maven is a great tool when you know how to use it. Maven (at core) is a dependency manager.
You include in your pom.xml (similar in function to the build.xml from Ant) all the librairies your project depends on (example : apache commons) along with their version and Maven get them directly from a repository (by default, the central maven repository)
Then you do not have to manually install any jar to make your project work. All is downloaded and cached on your local machine. You can even create an enterprise repository where you put all the jars needed by your company
Maven uses the concept of artifacts which are pre-built library projects with their own dependencies
To mavenize a project, you'll have to write a pom.xml describing your project (examples are numerous), get rid of your libs directory (or whatever classpath you described under Eclipse) and add all your dependencies to your pom.xml
You could also check Mavenizer for a first-start
But Maven is a lot more what i've just said. Read the docs, read poms from librairies and you'll get used to it quickly ;-)
If you use the M2Eclipse plugin from Sonatype, it's just a matter of right clicking the project in the package explorer and choosing Enable Dependency Management in the Maven menu. You are also advised to adjust the directories that contain the sources to the Maven standard directory layout but if you absolutely can't, you can configure that later.
Apart from that: Well, look for tutorials and documentation (for example there is the free book Better builds with Maven. Maven is very complex (yes, I don't think it is simple) and very powerful.

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

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.
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?
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.
From the Maven Eclipse Plugin FAQ
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>
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
As mentioned in How to download sources and javadoc artifacts with Maven Eclipse plugin from other repository?, you can do this:
In Eclipse go to Windows-> Preferences-> Maven. Check the box that says "Download Artifact Javadoc." That has worked well for me.
You might consider just avoiding this problem completely by installing the javadoc jar into your local repository manually using the install-file goal and passing in the -Dclassifier=javadoc option. Once you do that the .classpath that mvn generates should be correct.
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.
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.
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.
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.
2. If it’s a maven project
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.
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.
3. If it’s Maven project and we are setting the default behavior:
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.
Click Windows – preferences – select Maven and click the checkbox Download Artifact Javadoc as shown below
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.
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.
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.
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

Categories

Resources