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?
Related
I'm getting an error when I try to wrap the Jar to exe through Launch4j.
I have added the library already in the NetBeans IDE and also for the Project but still the error persists.
The Jar is running without any problems but when I try to wrap it, I'm getting always that issue warning:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout
....
....
Caused by: java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 17 more
How can I resolve this?
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="HelaTergo" default="default" basedir=".">
<description>Builds, tests, and runs the project HelaTergo.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="HelaTergo-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
CSS:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
Class-Path: lib/AbsoluteLayout.jar
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>C:\Users\ckoca\Documents\NetBeansProjects\HelaTergo\dist\HelaTergo.jar</jar>
<outfile>C:\Users\ckoca\OneDrive - COMPUTACENTER\Desktop\SerkoBib.exe</outfile>
<errTitle>Bitte Java vorerst installieren</errTitle>
<cmdLine></cmdLine>
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>C:\Users\ckoca\Documents\Icons\Icons8-Windows-8-Business-Department.ico</icon>
<classPath>
<mainClass>helaTergo.HomeHelaTergo</mainClass>
<cp>lib/AbsoluteLayout.jar</cp>
</classPath>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.6.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>1.0.0.0</txtFileVersion>
<fileDescription>Serko Library Software</fileDescription>
<copyright>Computacenter</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>SerkoBib</productName>
<companyName>Computacenter</companyName>
<internalName>SerkoBib</internalName>
<originalFilename>SerkoBib.exe</originalFilename>
<trademarks></trademarks>
<language>ENGLISH_US</language>
</versionInfo>
</launch4jConfig>
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
I can't compile following with JDK8 & Ant v1.9.4 with CLI.
build.xml:
<?xml version="1.0" ?>
<project default="Compile">
<target name="Compile">
<mkdir dir="classes"/>
<javac
srcdir="src"
includes="**/*.java"
destdir="classes"
source="1.8"
target="1.8"
debug="false">
</javac>
</target>
</project>
Error:
ction.java:118: error: cannot find symbol
[javac] userId= Long.parseUnsignedLong(uid);
[javac] ^
[javac] symbol: method parseUnsignedLong(String)
[javac] location: class Long
[javac] 1 error
BUILD FAILED E:\dbcommon\build.xml: 176: Compile failed; see the
compiler error output for details.
Of course the package exists and it works within Eclipse, but not with the CLI! I only have this JDK installed, no other version, JAVA_HOME is set to JDK (not the included JRE)!
Any suggestions would be great!
Edit the ANT HOME path in the Eclipse.
Right click on the build.xml file >> Run as >> External tool configurations >> Select the classpath tab.
Now change the ANT Home path from here.
Anybody knows about this kind of build failure on build.xml ?
build.xml is genereated automatically by Eclipse.
BUILD FAILED
E:\EclipseWorkspace\Launcher3\build.xml:48: Class not found: javac1.8
build.xml:48 is as following.
<javac debug="true" debuglevel="${debuglevel}" destdir="bin/classes" includeantruntime="false" source="${source}" target="${target}">
do you have a correctly installed and CONFIGURED jdk?
The message doesn't look so, as the compiler (javac) could not be found
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.