JAXWS-RI WSGEN configure to use specific JDK - java

I am currently trying to compile an application in CruiseControl using ANT but get an UnsupportedClassVersionError. The setup is as follows:
Environment: Windows server 2012
IDE: Eclipse Luna running JDK 8
Build server: CruiseControl 2.4.1 running on JDK 6
Build tool: ANT
Compiler: JDK 8 update 102
JAXWS-RI: 2.2.10
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.

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

Related

Ant file not able to run Java application via class files

I am using Ant to run my Java application. I have my main in Subscriber class which uses other libraries. So I wanted to run the Controller.Subscriber. But I get the following bug:
[java] Error: A JNI error has occurred, please check your installation and try again
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/paho/client/mqttv3/MqttCallback
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
[java] at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
[java] at java.lang.Class.getMethod0(Class.java:3018)
[java] at java.lang.Class.getMethod(Class.java:1784)
[java] at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
[java] Caused by: java.lang.ClassNotFoundException: org.eclipse.paho.client.mqttv3.MqttCallback
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 7 more
[java] Java Result: 1
My Ant file is the following:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
</project>
The path to the Subscriber class: target/classes/Controller/Subscriber.class
What am I doing wrong? Do I have to first to create jar file from my class files to can run the java program or can I execute the class files? Or do I miss a parameter in my java command?
I also tried the following Ant file by giving explicit classpath:
<project default="run">
<target name="run">
<java classname="Controller.Subscriber" fork="true" classpath="classpath">
<classpath>
<pathelement path="target/classes"/>
</classpath>
</java>
</target>
<path id="classpath">
<fileset dir="target">
<include name="*.jar"/>
</fileset>
</target>
</project>
But I am getting the same error message.
I have found the solution to the problem: I have to use classpathref instead of classpath. For some reason classpath="classpath" does not read the id "classpath". But classpathref solved the problem.

Error in a build.xml when using ANT

I write a java package, and I want to compile it into .class files first and then package it. Following codes are what I do in my ant script. Under the directory of "src/compressScript" are four java class I wrote.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project basedir="."default="compileJava" name="compileJava">
<target name="compileJava">
<mkdir dir="buildTest"/>
<javac includeantruntime="false" srcdir="src/compressScript" destdir="buildTest"/>
</target>
</project>
When I try to use javac task of ANT to run this scirpt, the error is like this:
Buildfile: C:\Users\di_yu\workspace\AffirmedNetworks\buildTest.xml
compileJava:
BUILD FAILED
C:\Users\di_yu\workspace\AffirmedNetworks\buildTest.xml:6:java.lang.UnsupportedClassVersionError: com/sun/tools/javac/Main : Unsupported major.minor version 52.0
Total time: 545 milliseconds
I check my compiler, the installed JRE is JRE 7.0 and the compiler compliance level is 1.7. So what's the problem?

Using external libraries in Java

Here's the error I keep getting at runtime:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Note, this is a runtime error, not a compile-time one. Both tasks in my build.xml have an identical classpath set, and the compile task runs fine every single time:
<path id="classpath">
<fileset dir="lib" includes="*.jar" />
</path>
<target name="compile">
<mkdir dir="build/classes"/>
<javac
srcdir="src"
classpathref="classpath"
includeantruntime="false"
destdir="build/classes"
/>
</target>
...
<target name="run" depends="clean,compile,jar">
<java
jar="build/jar/${project.name}.jar"
fork="true"
classpathref="classpath"
>
<sysproperty key="java.library.path" path="${path.lib}/windows"/>
</java>
</target>
Trying to run the jar via command-line manually yields the same result:
java -cp .:lib/*.jar -Djava.library.path=lib/windows -jar build/jar/JUtopia.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Note that the library jarfile is ok:
bash-3.1$ jar -tf lib/lwjgl.jar | grep LWJGLException
org/lwjgl/LWJGLException.class
And the native libraries are in place:
bash-3.1$ ls lib/windows/lwjgl.dll
lib/windows/lwjgl.dll
The question: where the blazes have I gone wrong? I've been beating at this problem for nearly 3 days. Any help would be much appreciated.
Full result stack:
clean:
[delete] Deleting directory C:\Users\mkumpan\Projects\JUtopia\build
compile:
[mkdir] Created dir: C:\Users\mkumpan\Projects\JUtopia\build\classes
[javac] Compiling 12 source files to C:\Users\mkumpan\Projects\JUtopia\build\classes
jar:
[mkdir] Created dir: C:\Users\mkumpan\Projects\JUtopia\build\jar
[jar] Building jar: C:\Users\mkumpan\Projects\JUtopia\build\jar\JUtopia.jar
run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
[java] at JUtopia.<init>(Unknown Source)
[java] at JUtopia.main(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.lwjgl.LWJGLException
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[java] ... 2 more
P.S.: Note, I'm using Console2 with bash in a windows environment for my commandline work, thus the windows natives yet linux shell syntax. Using vanilla cmd to run the jar yields the same result.
-jar...
When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored. - reference
try setting the Class-Path in the JAR
Alternatively try running without the -Jar option, by specifying the main class on the command line
One of the possible causes is that while loading the class LWJGLException it also references another class which can't be found on the classpath. Hence the reported error is sometimes not clear.
Important here is thet you have this NoClassDefFoundError and not ClassNotFoundException which is the error you assume you are having: it cannot find the class LWHLException, yes it can ! But it cannot load it....

Java can't find existing method in a class

I have jar archive build with Ant 1.9.1
When I launch class from it I get the following exception:
Caused by Java exception: java.lang.NoSuchMethodError: com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput.setChecked(Z)V
at com.blablabla.kats.drivers.CheckBox.check(CheckBox.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.blablabla.kats.utils.Operation.doInvoke(Operation.java:142)
at com.blablabla.kats.utils.Operation.invokeMethod(Operation.java:117)
at com.blablabla.kats.model.handles.ElementOperationHandle.invokeOn(ElementOperationHandle.java:33)
at com.blablabla.kats.model.statements.DirectAction.execute(DirectAction.java:45)
at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
at com.blablabla.kats.model.Procedure.call(Procedure.java:46)
at com.blablabla.kats.model.statements.Invocation.execute(Invocation.java:48)
at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
at com.blablabla.kats.model.TestCase.execute(TestCase.java:41)
at com.blablabla.kats.model.TestSuite.execute(TestSuite.java:45)
at com.blablabla.kats.model.TestProgram.execute(TestProgram.java:40)
at com.blablabla.kats.Main.main(Main.java:158)
When I compile "com.blablabla.kats.drivers.CheckBox" class by javac and replace corresponding file in jar all works fine.
I use htmlunit 2.12
java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
corresponding Ant task:
<path id="classpath.libraries">
<fileset dir="${basedir}/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile">
<javac srcdir="${basedir}/src/java" destdir="classes" debug="true" source="1.5" target="1.5">
<classpath refid="classpath.libraries" />
</javac>
</target>
${basedir}/lib contains a lot of jars.
The main are
kats.jar - my project, containing com.blablabla.kats.drivers.CheckBox
htmlunit-2.12.jar - where com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput.setChecked(Z) is.
Why it can happen?
The only difference that i see is, you are using 1.5 in ant script where as looking at the java version you are using java6 to run it. I am not sure if this may make a big difference as it should be backward compatible, but still give it a try. Change this version to 1.6 in ant build.xml
I found out that I didn't delete old compiled class.
When I cleaned up compiled classes all worked fine.

How do I add the j2ee.jar to a Java2WSDL ant script programmatically?

I am using IBM's Rational Application Developer. I have an ant script that contains the Java2WSDL task. When I run it via IBM, it gives compiler errors unless I include the j2ee.jar file in the classpath via the run tool (it does not pick up the jar files in the classpath in the script). However, I need to be able to call this script programmatically, and it is giving me this error: "java.lang.NoClassDefFoundError: org.eclipse.core.runtime.CoreException" I'm not sure which jars need to be added or where? Since a simple echo script runs, I assume that it is the j2ee.jar or another ant jar that needs to be added. I've added it to the project's buildpath, but that doesn't help. (I also have ant.jar, wsanttasks.jar, all the ant jars from the plugin, tools.jar, remoteAnt.jar, and the swt - all which are included in the buildpath when you run the script by itself.)
Script:
<?xml version="1.0" encoding="UTF-8"?>
<project default="build" basedir=".">
<path id="lib.path">
<fileset dir="C:\Program Files\IBM\WebSphere\AppServer\lib" includes="*.jar"/>
<!--
Adding these does not help.
<fileset dir="C:\Program Files\IBM\SDP70Shared\plugins\org.apache.ant_1.6.5\lib" includes="*.jar"/>
<fileset dir="C:\Program Files\IBM\SDP70\jdk\lib" includes="*.jar"/>
<fileset dir="C:\Program Files\IBM\SDP70\configuration\org.eclipse.osgi\bundles\1139\1\.cp\lib" includes="*.jar"/>
<fileset dir="C:\Program Files\IBM\SDP70Shared\plugins" includes="*.jar"/>
-->
</path>
<taskdef name="java2wsdl"
classname="com.ibm.websphere.ant.tasks.Java2WSDL">
<classpath refid="lib.path"/>
</taskdef>
<target name="build">
<echo message="Beginning build"/>
<javac srcdir="C:\J2W_Test\Java2Wsdl_Example"
destdir="C:\J2W_Test\Java2Wsdl_Example">
<classpath refid="lib.path"/>
<include name="WSExample.java"/>
</javac>
<echo message="Set up javac"/>
<echo message="Running java2wsdl"/>
<java2wsdl output="C:\J2W_Test\Java2Wsdl_Example\example\META-INF\wsdl\WSExample.wsdl"
classpath="C:\J2W_Test\Java2Wsdl_Example"
className= "example.WSExample"
namespace="http://example"
namespaceImpl="http://example"
location="http://localhost:9080/example/services/WSExample"
style="document"
use="literal">
<mapping namespace="http://example" package="example"/>
</java2wsdl>
<echo message="Complete"/>
</target>
</project>
Code:
File buildFile = new File("build.xml");
Project p = new Project();
p.setUserProperty("ant.file", buildFile.getAbsolutePath());
DefaultLogger consoleLogger = new DefaultLogger();
consoleLogger.setErrorPrintStream(System.err);
consoleLogger.setOutputPrintStream(System.out);
consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
p.addBuildListener(consoleLogger);
try {
p.fireBuildStarted();
p.init();
ProjectHelper helper = ProjectHelper.getProjectHelper();
p.addReference("ant.projectHelper", helper);
helper.parse(p, buildFile);
p.executeTarget(p.getDefaultTarget());
p.fireBuildFinished(null);
} catch (BuildException e) {
p.fireBuildFinished(e);
}
Error:
[java2wsdl] java.lang.NoClassDefFoundError: org.eclipse.core.runtime.CoreException
[java2wsdl] at java.lang.J9VMInternals.verifyImpl(Native Method)
[java2wsdl] at java.lang.J9VMInternals.verify(J9VMInternals.java:68)
[java2wsdl] at java.lang.J9VMInternals.initialize(J9VMInternals.java:129)
[java2wsdl] at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getDiscoveredServiceProviders(ServiceProviderManager.java:378)
[java2wsdl] at com.ibm.ws.webservices.multiprotocol.discovery.ServiceProviderManager.getAllServiceProviders(ServiceProviderManager.java:214)
[java2wsdl] at com.ibm.ws.webservices.wsdl.fromJava.Emitter.initPluggableBindings(Emitter.java:2704)
[java2wsdl] at com.ibm.ws.webservices.wsdl.fromJava.Emitter.<init>(Emitter.java:389)
[java2wsdl] at com.ibm.ws.webservices.tools.ant.Java2WSDL.execute(Java2WSDL.java:122)
[java2wsdl] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
[java2wsdl] at org.apache.tools.ant.Task.perform(Task.java:364)
[java2wsdl] at org.apache.tools.ant.Target.execute(Target.java:341)
[java2wsdl] at org.apache.tools.ant.Target.performTasks(Target.java:369)
[java2wsdl] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
[java2wsdl] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
[java2wsdl] at att.ant.RunAnt.main(RunAnt.java:32)
A jarfinder search suggests that because you are running outside of the Rational environment, you need access to the Eclipse core jars (perhaps) where that file might be contained.

Categories