Archive

Archive for novembre 2011

WTP Eclipse project generation from Maven configuration

The maven ‘eclipse’ plugin is a bit outdated, but very useful. I had some issues when generating eclipse configuration specifically for web projects.
Here is a description on how I managed to configure the plugin finally !

This configuration generates an Eclipse project configuration when you run mvn eclipse:eclipse. All you have to do then is to import the project into Eclipse by running the File>Import menu entry in Eclipse

This configuration fixes some issues I used to have with mvn-generated Eclipse projects :

  • utf-8 encoding for all text files
  • good versions in project’s facets (servlet 3.0, java 1.6, javascript 1.0)
  • Correct web-specific settings (web root directory location, and use of the jar dependencies in the webapp)
  • Spring-enabled project nature

The plugins section of the pom.xml looks like that :

    <properties>
		<java.version>1.6</java.version>
		<servlet-api.version>3.0</servlet-api.version>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<plugins>

	    ...

		<plugin>
		    <groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>2.3.2</version>
			<configuration>
				<source>${java.version}</source>
				<target>${java.version}</target>
			</configuration>
		</plugin>

		<!-- Settings for generating eclipse project -->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-eclipse-plugin</artifactId>
			<version>2.8</version>
			<configuration>
				<wtpversion>2.0</wtpversion>
				<downloadSources>false</downloadSources>
				<downloadJavadocs>false</downloadJavadocs>
				<additionalConfig>
					<file>
						<name>.settings/org.eclipse.wst.common.project.facet.core.xml</name>
						<content><![CDATA[
							<faceted-project>
							  <fixed facet="jst.java"/>
							  <fixed facet="jst.web"/>
							  <installed facet="jst.java" version="${java.version}"/>
							  <installed facet="jst.web" version="${servlet-api.version}"/>
							  <installed facet="wst.jsdt.web" version="1.0"/>
							</faceted-project>
						]]></content>
					</file>
					<file>
						<name>.settings/org.eclipse.core.resources.prefs</name>
						<content><![CDATA[eclipse.preferences.version=1
encoding/<project>=${project.build.sourceEncoding}]]>
						</content>
					</file>
				</additionalConfig>
				<additionalProjectnatures>
				   <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
				</additionalProjectnatures>
			</configuration>
		</plugin>

	</plugins>

You may also have to ensure that you gave a value to the M2_REPO variable in the Eclipse settings points to your local .m2/repository.

Publicités
Catégories :Uncategorized