How to download sources and JavaDoc with maven in Eclipse

Posted on December 18, 2016


In this post, we will show you how to download sources and JavaDoc for dependencies of your maven project in Eclipse IDE.

Technologies used –

  • Spring Tool Suite (Version: 3.8.2.RELEASE) or Eclipse Mars.2 (4.5.2)
  • Maven 3.3.9
  • JavaSE 1.8

Let's begin step by step...

Step 1 - Create a Maven project

Go to New menu → Other..Maven → Maven Project and click on Next.

In New Maven Project wizard, click on Next.

maven-source-dwn1.png

Step 2 - Select Maven project archetype

Select archetype as maven-architype-quickstart and click on Next.

maven-source-dwn2.png

Step 3 - Add project information

In the next wizard, add project information as shown below and click on Finish.

maven-source-dwn3.png

 

Step 4 - Edit pom.xml file and update project

Open pom.xml file and write the following code in it.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.boraji.tutorail</groupId>
	<artifactId>maven-project</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>maven-project</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
		</dependency>
	</dependencies>

	<build>
		<sourceDirectory>src/main/java</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>

After changes in pom.xml update your project. To update maven project, right click on project → Maven Update Project...

maven-source-dwn4.png

Step 5 - Review project directory structure

Here is the final project structure.

maven-source-dwn5.png

Step 6 - Download source and JavaDoc

To download sources for dependencies of maven project, right click on project → Maven Download Sources.

maven-source-dwn6.png

Similarly to download JavaDoc for dependencies of maven project, right click on project → Maven Download JavaDoc.

 

Step 7 - View Source and JavaDoc

Double click on class file to view the source and javadoc as show below.

maven-source-dwn7.png