Home > Eclipse, Java, Maven, Spring, Tools > Maven-Eclipse-Spring Integration

Maven-Eclipse-Spring Integration


In every new project I write I use maven and Eclipse. On most of these projects I use Spring as well – and I’m probably not the only one around doing it.

The problem I always run in to is how to configure everything to work properly – so once I finally got a properly working configuration, I had to write it down:

Simple Configuration – Maven + Eclipse
This configuration in your pom.xml will generate your .project and .classpath files (and a few more).

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
</plugin>

Slightly Advanced Configuration – Maven + Eclipse
This configuration will also automatically download sources and javadocs of any dependency you add into your project – very useful when working with open source software.

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
	<configuration>
		<downloadSources>true</downloadSources>
		<downloadJavadocs>true</downloadJavadocs>
	</configuration>
</plugin>

Spring Specific Configuration – Add Support in Eclipse
The additionalProjectnatures and additionalBuildcommands sections add the springnature and springbuilder to the project and allow you to get Spring specific highlights and notifications on your project (e.g. Icons on each class indicating if it is a Spring bean)

<plugin>
	<artifactId>maven-eclipse-plugin</artifactId>
	<version>2.9</version>
	<configuration>
		<additionalProjectnatures>
			<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
		</additionalProjectnatures>
		<additionalBuildcommands>
			<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
		</additionalBuildcommands>
		<downloadSources>true</downloadSources>
		<downloadJavadocs>true</downloadJavadocs>
	</configuration>
</plugin>

The Maven-Eclipse Plugin has a few more configurations and abilities, you can read more about it on http://maven.apache.org/plugins/maven-eclipse-plugin/

Advertisements
  1. January 18, 2013 at 19:56

    What is funny is that if I run “mvn package” in console or in eclipse, it works fine and even produces war containing all necessary jars. Only Eclipse complains with “The project was not built since its build path is incomplete. Cannot find the class file for org.slf4j.Logger…”. If I compare the project with some other computer (where project works fine), I notice that there are quite a few libraries missing under “Maven dependencies” listing in Eclipse. Eventhough they are in the packaged war and they can be found also under repository folder.

    • March 29, 2013 at 15:36

      You usually need to right-click on the project and choose “Maven->Update Project Configuration” and check all the check-boxes to ensure eclipse downloads all the dependencies to the local repository.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: