Mercurial > hg > Blog
view content/Maven/cross-jdk-project-files.md @ 0:4cd9b65e10e4
initial import of the pelican based blog
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Fri, 28 Jun 2013 08:48:58 +0200 |
parents | |
children | 1d9382b0329b |
line wrap: on
line source
Title: Cross JDK project files with Maven Date: 2008-03-19 Lang: en Recently we switched the Mule build to be [based on JDK5](http://www.mulesource.org/display/MULECDEV/Building+from+Source) for some modules. This requires the Maven build to be JDK aware. While the JDK auto-activation of profiles get you to build the project from the commandline, IDE integration was a bit of pain. Now that the [maven-eclipse-plugin](http://maven.apache.org/plugins/maven-eclipse-plugin/) has released v2.5 there's finally support for JDK aware project files. You can add the following to your POMs in order to select a specific JDK for your project :::xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <classpathContainers> <classpathContainer> org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/thisismyjdk </classpathContainer> </classpathContainers> </configuration> </plugin> While this solution is better than nothing already I really don't like how you're forced to hard-code the JDK names into the POM. Fortunately, Maven allows you to specify properties and property resolution works in this case, too. So all you have to do is to define a property placeholder instead of your JDK name in config above, like this: :::xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <classpathContainers> <classpathContainer> org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/${jdk} </classpathContainer> </classpathContainers> </configuration> </plugin> Then go and define a property in the pom (for the default value). Anyone who uses a different JDK can specify the name to use on the commandline now using mvn -Djdk=sun-jdk-1.4.2.14 eclipse:eclipse