1

My problem is: Test cases are green on local, but some are failed on hudson server because of non-supported jdk version. Local is ibm jdk1.6 sr4 windows, but hudson server installed ibm jdk1.6 sr9 linux. "This Java virtual machine is not supported for use with Blaze Advisor because the implementation of java.beans.Introspector failed to pass validation."

I was told Hudson server cannot change to other jdk, so I am think is there any work around to bypass those failure? Can I tell maven to compile project with specific jdk? Like, 1.6 version with sr4, instead of sr9. Also I need maven to download sr4 as dependency coz there is no this version on server.

Seems it's hard to do this as I searched out. So what else option i could have?

Thanks for any suggestion.

Sarstime
  • 184
  • 1
  • 3
  • 14
  • You can change versions among Java 1.3, 1.4, 5, 6, and perhaps 7. But minor versions, might not be there. – Nishant Sep 19 '12 at 14:56
  • You can specify the precise Java SDK release to use, but it has to be available on the server. See: [Compile Using a Different JDK](http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html) – noahlz Sep 19 '12 at 15:42

3 Answers3

3

Maven should start with the java specified in JAVA_HOME if you need to use a different version I would use the toolchain plugin to run your build with a specified jdk version. It will require the version be already installed on the server though.

http://maven.apache.org/guides/mini/guide-using-toolchains.html

You will need to add the plugin to your pom and add a toolchains.xml file.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-toolchains-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>toolchain</goal>
            </goals>
      </execution>
    </executions>
    <configuration>
      <toolchains>
        <jdk>
          <version>1.5</version>
          <vendor>sun</vendor>
        </jdk>
      </toolchains>
    </configuration>
  </plugin>

toolchains.xml file added to .m2 folder which specifies the install location for the jdk

<?xml version="1.0" encoding="UTF8"?>
<toolchains>
  <toolchain>
     <type>jdk</type>
     <provides>
         <version>1.5</version>
         <vendor>sun</vendor>
         <id>default</id>
     </provides>
     <configuration>
        <jdkHome>/path/to/jdk/1.5</jdkHome>
     </configuration>
  </toolchain>
Adam Schreiner
  • 504
  • 2
  • 6
  • That's my pain point. Server only installed a non-supported version JDK. – Sarstime Sep 20 '12 at 02:33
  • @Sarstime I don't think there is anyway around that, if you can't get it installed directly you could try installing the JDK version you need through the hudson config menu (Manage->Configure System->JDK Installations) – Adam Schreiner Sep 20 '12 at 16:32
  • yes, you are right. I found there is not way to work around. So my solution is change my test cases to bypass those conflicts. – Sarstime Sep 21 '12 at 05:44
0

Are you sure? The Hudson should support switching JDKs, I've done it in Jenkins. In worst case you could specify JAVA_HOME env variable in the Hudson build. It is impossible to change in maven, because maven itself needs JDK to start.

kan
  • 28,279
  • 7
  • 71
  • 101
  • Yes, maven supports switch jdk, but what I need to use 1.6 different minor version, sr4, not sr9. Seems maven doesn't support that. – Sarstime Sep 20 '12 at 02:31
  • @Sarstime No, maven doesn't support jdk switch, it is impossible as I said. It just passes `-source` and `-target` options to the javac. – kan Sep 20 '12 at 08:10
0

You can configure this in your maven-compiler-plugin

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

You can also use profiles -P to set versions based on environments.

basiljames
  • 4,777
  • 4
  • 24
  • 41
  • This corresponds to the `-source` and `-target` flags used by `javac` but does not set the actual compiler. See [javac documentation](http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html) – noahlz Sep 19 '12 at 15:40
  • in order for this configuration to work, the javac executable would have to be specified, and the build 'forked' to use the different jvm. see http://stackoverflow.com/a/4724062/127971 (which in turn points back to this answer, actually: http://stackoverflow.com/a/12498238/201498 ) – michael Mar 28 '14 at 18:04