javaantjava-8jax-wscruisecontrol

JAXWS-RI WSGEN configure to use specific JDK


I am currently trying to compile an application in CruiseControl using ANT but get an UnsupportedClassVersionError. The setup is as follows:

CruiseControl is installed as a service and during startup JAVA_HOME is set to JDK 6 in a file called wrapper.conf. As target version is Java 8 another env variable is also set.

set.JAVA_HOME=C:/jdk1.6
set.JAVA_HOME_JDK8=C:/jdk1.8.0_102

In the ANT build scripts the javac task has fork set to true and specifies the path to the java executable like this:

<property name="javac.fork" value="yes"/>
<property environment="env"/>
<property name="javac.location" value="${env.JAVA_HOME_JDK8}\\bin\\javac.exe"/>

<javac includeantruntime="false" destdir="${builddir}" debug="true"
 target="1.8" source="1.8" debuglevel="lines,vars,source" 
 fork="${javac.fork}" executable="${javac.location}">

The above setup works well but fails when I try to use JAXWS-RI to create artifacts. The specific error reported is:

java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
    at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:384)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    at org.apache.tools.ant.Main.runBuild(Main.java:668)
    at org.apache.tools.ant.Main.startAnt(Main.java:187)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: C:\path\build.xml:133: The following error occurred while executing this line:
java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
    at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:539)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:384)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
    ... 12 more
Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1225)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:37)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:382)
    ... 20 more
Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at com.sun.tools.ws.wscompile.WsgenOptions.getClass(WsgenOptions.java:305)
    at com.sun.tools.ws.wscompile.WsgenOptions.validateEndpointClass(WsgenOptions.java:244)
    at com.sun.tools.ws.wscompile.WsgenOptions.validate(WsgenOptions.java:235)
    at com.sun.tools.ws.wscompile.WsgenTool.run(WsgenTool.java:131)
    at com.sun.tools.ws.ant.WsGen2.runInVm(WsGen2.java:357)
    at com.sun.tools.ws.ant.WsTask2.execute(WsTask2.java:423)
    at com.sun.tools.ws.ant.WsGen2.execute(WsGen2.java:351)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
    at org.apache.tools.ant.Task.perform(Task.java:364)
    at org.apache.tools.ant.Target.execute(Target.java:341)
    at org.apache.tools.ant.Target.performTasks(Target.java:369)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
    ... 23 more

As far as I can see it is thrown because WSGEN uses JAVA_HOME (pointing to JDK 6) to find the Java executable subsequently used to generate stuff.

WSSGEN setup is:

<target name="wsgen-compile">
    <mkdir dir="${builddir}"/>
    <javac includeantruntime="false" destdir="${builddir}" debug="true" target="1.8" source="1.8" debuglevel="lines,vars,source" fork="${javac.fork}" executable="${javac.location}">    
        <src path="${src.tmp}" />    
        <classpath>    
            <pathelement path="${classpath}"/>    
            <pathelement path="${builddir}/../../common/bin"/>    
            <pathelement path="${builddir}/../../server/bin"/>    
            <fileset dir="${libdir}">    
                <include name="*.jar"/>    
            </fileset>    
        </classpath>    
    </javac>    
</target>    

<target name="wsgen-generate">    
    <taskdef name="wsgen" classname="com.sun.tools.ws.ant.WsGen2">    
        <classpath>    
            <fileset dir="${webserviceslibdir}/jax/jaxws-ri/lib">    
                <include name="*.jar"/>    
            </fileset>    
        </classpath>                
    </taskdef>    

    <wsgen verbose="true"    
            genwsdl="true"    
            xendorsed="false"    
            keep="true"    
            resourcedestdir="properties"    
            destdir="${src.tmp}"    
            sei="com.nordea.nordiccms.server.webservices.${service}">               
        <classpath>    
            <pathelement path="${classpath}"/>    
            <pathelement path="${builddir}/../../common/bin"/>    
            <pathelement path="${builddir}/../../server/bin"/>    
            <fileset dir="${libdir}">    
                <include name="*.jar"/>    
            </fileset>    
        </classpath>     
        <arg value="J.java_home"/>    
    </wsgen>    

    <delete>    
        <fileset dir="${src.tmp}">    
            <include name="**/*.class"/>    
        </fileset>    
    </delete>    
</target>    

<target name="wsgen" depends="compile">    
    <echo message=""/>    
    <echo message="Building ${distributionnameserver} WebService files"/>    
    <echo message="----------"/>    
    <mkdir dir="${builddir}/wsgen"/>    

    <delete dir="${src.tmp}"/>    
    <mkdir dir="${src.tmp}"/>    

    <ant target="wsgen-generate">    
        <property name="service" value="Service1"/>    
    </ant>          

    <ant target="wsgen-compile"/>        
    <delete dir="${src.tmp}"/>    
</target>

I want to configure WSGEN to use JDK 8 instead of JDK 6 while compiling, but I have so far been unable to do so. Does anybody know how I might solve this problem? I should mention that upgrading CruiseControl to run on JDK8 is not an option at this point.


Solution

  • The error has the following...

    Caused by: java.lang.UnsupportedClassVersionError: com/company/area/thing/services/Service1 : Unsupported major.minor version 52.0

    /*snip*/

    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

    at com.sun.tools.ws.wscompile.WsgenOptions.getClass(WsgenOptions.java:305)

    The error is saying that the version of the Java Runtime (the JRE) running Ant is older than JRE version 52.0. JRE 52.0 is the major number for Java SE 8 (see How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version).

    The JRE running Ant is trying to interact with the Java class com/company/area/thing/services/Service1. However, the Service1 class was compiled with Java 8. The older JRE running Ant doesn't know how to handle Java 8 classes, so the build fails.

    Try running Ant with Java 8. Set JAVA_HOME to point to an installation of JDK 8.

    Use the following build.xml script to verify the version of Java being used:

    <project name="ant-jdk-version">
        <echo>Java Version via Ant: ${ant.java.version}</echo>
        <echo>Java Version System Prop: ${java.version}</echo>
    </project>
    

    The script should output something similar to...

     [echo] Java Version via Ant: 1.8
     [echo] Java Version System Prop: 1.8.0_60