views:

359

answers:

3

Hi all. I am trying to build a Hudson plugin I've modified and it requires jdk1.6. This is fine, but I don't see how I can tell maven where the different jdk is. I've found few mentions on the internet but they don't seem to apply to me. Some suggest adding some config to .m2/settings.xml but I don't have a settings.xml. Plus, I don't want to use 1.6 for all maven builds.

One kink is I am using mvn in cygwin, if that matters at all. It appears I should be able to make the specification in the project pom file, but the existing pom is pretty bare.

So bottom line is, is there a way to specify a jdk for a single invocation of maven?

+2  A: 

So bottom line is, is there a way to specify a jdk for a single invocation of maven?

Temporarily change your JAVA_HOME.

Pascal Thivent
A: 

Hudson also allows you to define several Java runtimes, and let you invoke Maven with one of these. Have a closer look on the configuration page.

Thorbjørn Ravn Andersen
The OP is building an hudson plugin on the command line, not under hudson (at least, this is my understanding).
Pascal Thivent
I reread the question - I think you read it right.
Thorbjørn Ravn Andersen
A: 

I say you setup JAVA_HOME like Pascal is saying: In cygwin if you use bash as your shell should be "export JAVA_HOME=/cygdrive/c/pathtothejdk" And it never harms to also export the java bin dir to the PATH with "export PATH=${JAVA_HOME}/bin:${PATH}"

and also add maven-enforce-plugin to make sure the right jdk is used. This is a good practice for your pom.

<build>
 <plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <executions>
        <execution>
          <id>enforce-versions</id>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireJavaVersion>
                <version>1.6</version>
              </requireJavaVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

http://maven.apache.org/plugins/maven-enforcer-plugin/usage.html

feniix