java.lang.AssertionError in JDK 8u202 - java

I am currently updating one of my Java projects from JDK 1.5.0_14 to JDK 8u202.
Here is my problem:
I can build the project with JDK 1.5.0_14 and JDK 8u202.
But as soon as I change one single line of code (no matter what) I get the following java.lang.AssertionError (see at the end of this post).
When I downgrade to JDK 1.5.0_14, build the project once and upgrade to JDK 8u202, I can build again without any error.
But again, after changing any line of code (only one character), I get the error below.
Does anybody have an idea how to resolve this issue?
FYI: I am using NetBeans 8.0.2.
ant -f D:\\NetBeansProjects\\MyProject -Dnb.internal.action.name=build jar
init:
Deleting: D:\NetBeansProjects\MyProject\build\built-jar.properties
deps-jar:
Updating property file: D:\NetBeansProjects\MyProject\build\built-jar.properties
Compiling 1 source file to D:\NetBeansProjects\MyProject\build\classes
An exception has occurred in the compiler (1.8.0_202). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: the -J flag should be caught by the launcher.
at com.sun.tools.javac.main.Option$20.process(Option.java:331)
at com.sun.tools.javac.main.Main.processArgs(Main.java:260)
at com.sun.tools.javac.main.Main.compile(Main.java:414)
at com.sun.tools.javac.main.Main.compile(Main.java:381)
at com.sun.tools.javac.main.Main.compile(Main.java:370)
at com.sun.tools.javac.main.Main.compile(Main.java:361)
at com.sun.tools.javac.Main.compile(Main.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.taskdefs.compilers.Javac13.execute(Javac13.java:56)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:1159)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:935)
at org.netbeans.modules.java.source.ant.JavacTask.execute(JavacTask.java:145)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)
D:\NetBeansProjects\MyProject\nbproject\build-impl.xml:910: The following error occurred while executing this line:
D:\NetBeansProjects\MyProject\nbproject\build-impl.xml:300: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
Here is the compilation and JAR building section from my build-impl.xml
<!--
===================
COMPILATION SECTION
===================
-->
<target name="-deps-jar-init" unless="built-jar.properties">
<property location="${build.dir}/built-jar.properties" name="built-jar.properties"/>
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
<echo level="warn" message="Cycle detected: MyProject was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
<touch file="${built-jar.properties}" verbose="false"/>
<property file="${built-jar.properties}" prefix="already.built.jar."/>
<antcall target="-warn-already-built-jar"/>
<propertyfile file="${built-jar.properties}">
<entry key="${basedir}" value=""/>
</propertyfile>
</target>
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
<target depends="init" name="-check-automatic-build">
<available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
</target>
<target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
<antcall target="clean"/>
</target>
<target depends="init,deps-jar" name="-pre-pre-compile">
<mkdir dir="${build.classes.dir}"/>
</target>
<target name="-pre-compile">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target if="do.depend.true" name="-compile-depend">
<pathconvert property="build.generated.subdirs">
<dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
<include name="*"/>
</dirset>
</pathconvert>
<j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
</target>
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile, -copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
<target if="has.persistence.xml" name="-copy-persistence-xml">
<mkdir dir="${build.classes.dir}/META-INF"/>
<copy todir="${build.classes.dir}/META-INF">
<fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/>
</copy>
</target>
<target name="-post-compile">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
<target name="-pre-compile-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
</target>
<target name="-post-compile-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
<!--
====================
JAR BUILDING SECTION
====================
-->
<target depends="init" name="-pre-pre-jar">
<dirname file="${dist.jar}" property="dist.jar.dir"/>
<mkdir dir="${dist.jar.dir}"/>
</target>
<target name="-pre-jar">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init" if="do.archive" name="-do-jar-create-manifest" unless="manifest.available">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<touch file="${tmp.manifest.file}" verbose="false"/>
</target>
<target depends="init" if="do.archive+manifest.available" name="-do-jar-copy-manifest">
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
<copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
</target>
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass">
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</target>
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+profile.available" name="-do-jar-set-profile">
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="Profile" value="${javac.profile}"/>
</manifest>
</target>
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-set-splashscreen">
<basename file="${application.splash}" property="splashscreen.basename"/>
<mkdir dir="${build.classes.dir}/META-INF"/>
<copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
<manifest file="${tmp.manifest.file}" mode="update">
<attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
</manifest>
</target>
<target depends="init,-init-macrodef-copylibs,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.mkdist" name="-do-jar-copylibs">
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<pathconvert property="run.classpath.with.dist.jar">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
</pathconvert>
<condition else="" property="jar.usage.message" value="To run this application from the command line without Ant, try:${line.separator}${platform.java} -cp ${run.classpath.with.dist.jar} ${main.class}">
<isset property="main.class.available"/>
</condition>
<condition else="debug" property="jar.usage.level" value="info">
<isset property="main.class.available"/>
</condition>
<echo level="${jar.usage.level}" message="${jar.usage.message}"/>
</target>
<target depends="-do-jar-copylibs" if="do.archive" name="-do-jar-delete-manifest">
<delete>
<fileset file="${tmp.manifest.file}"/>
</delete>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-jar,-do-jar-delete-manifest" name="-do-jar-without-libraries"/>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-do-jar-copylibs,-do-jar-delete-manifest" name="-do-jar-with-libraries"/>
<target name="-post-jar">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-jar,-do-jar-without-libraries,-do-jar-with-libraries,-post-jar" name="-do-jar"/>
<target depends="init,compile,-pre-jar,-do-jar,-post-jar" description="Build JAR." name="jar"/>

Hello Malawirel I don't know if it helps but if you have a ant project, the problem can be on the properties file of the ant project. If you have it please check it to see if the versions are correct and all is fine.

I finally managed to compile it. Here is what I did:
I changed the Source/Binary Format to JDK 8. See Using NetBeans 8 but getting below compilation error for Lambda expression on how to do that. I still could not compile it (in NetBeans 8.0.2).
I installed NetBeans IDE 10.0 and opened the project there. Then it compiled without any issues.
So seems like this was an issue in NetBeans.

Related

java.lang.NoClassDefFoundError ANT build

I am getting an error regarding the classpath in the run stage. The error is
run:
[java] java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver
[java] at java.lang.Class.getDeclaredMethods0(Native Method)
[java] at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
[java] at java.lang.Class.privateGetMethodRecursive(Unknown Source)
[java] at java.lang.Class.getMethod0(Unknown Source)
[java] at java.lang.Class.getMethod(Unknown Source)
[java] at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
[java] at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
[java] Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.WebDriver
[java] at java.net.URLClassLoader.findClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[java] at java.lang.ClassLoader.loadClass(Unknown Source)
[java] ... 7 more
[java] Error: A JNI error has occurred, please check your installation and try again
[java] Exception in thread "main"
[java] Java Result: 1
BUILD SUCCESSFUL
Total time: 1 second
This is the xml build code I have written. I am referencing the RunningPower jars folder and I believe the correct folder is being referenced as i able am able to compile. My base directory also contains a .classpath and .project file but not sure if they are important.
<?xml version="1.0" ?>
<project name="SeleniumProjectDataDriven" basedir="." default="run">
<target name="init">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/class" />
<property name="lib.dir" value="RunningPowerJars" />
</target>
<target name="clean" depends="init">
<delete dir="build"/>
</target>
<target name="compile" description="Compiles the code" depends="clean" >
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" description="Packages the code into jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/RunningPower.jar" basedir="build/class">
<manifest>
<attribute name="Main-Class" value="RunningPower"/>
</manifest>
</jar>
</target>
<target name="run" description="Run the jar file" depends="jar" >
<java jar="build/jar/RunningPower.jar" fork="true"/>
</target>
</project>
In my RunningPowerJars folder, they contain
junit-4.8.1.jar
ojdbc6.jar
poi-3.7-20101029.jar
selenium-java-2.46.0.jar
selenium-server-standalone-2.46.0.jar
testng-6.1.1.jar
Update (7:32 AM PST 8/21/2015)
<target name="run" description="Run the jar file" depends="jar" >
<java jar="build/jar/RunningPower.jar" fork="true">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</java>
</target>
I modified the code but ran into another error.
BUILD FAILED
C:\Users\dt208672\Perforce\depot\ebill\Automation\Selenium_eBill\RunningPower\build.xml:37: Problem: failed to create task or type classpath
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
The classpath is needed also when running the Jar file so that the JVM could find library classes. However, when using the jar attribute in the java task, "all classpath settings are ignored" (see https://ant.apache.org/manual/Tasks/java.html). The simplest way is to specify the main class and add the compiled Jar along with the library Jars located in the RunningPowerJars directory:
<target name="run" description="Run the jar file" depends="jar" >
<java classname="RunningPower" fork="true">
<classpath>
<pathelement location="build/jar/RunningPower.jar"/>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</java>
</target>
An unrelated note is that you could use the properties defined in init throughout the buildfile. For example, in the jar target you can use ${classes.dir} instead of repeating build/class.
It still doesn't make sense why the build would fail if the classpath element is added inside the java task when using the jar attribute. Although it is ignored, it is weird that it is failing with the "failed to create task or type" error.
Consider that when you use the -jar parameter using the java.exe in command line the classpath parameter is ignored, that also happens with the java task in ant.
So, what you must do is to provide the libraries you need to have available to the process launching that ant and that will suffice.
Once said that... where should you add those libraries then ? if you're launching from eclipse, you may add them on Window->preferences under Ant->Runtime->Global Entries.
If you're using some C.I. server like jenkins you could add them on numerous ways, I cannot give a direct answer because there could be many.
There is also an alternative. You may declare the dependency on the .jar MANIFEST.MF and put it under /lib or whatever inside that jar.

include maven-ant build libs in eclipse java project

I am struggling with maven-ant build with eclipse.
I did work like below steps.
[GUI] new java project
add build.xml in project top folder
run ant file and SUCCEED!
trying to code, but somehow auto completion does not work.(guessing eclipse can not read maven-ant dependency.path)
So I tried.
add ~/.m2/repository in build path as a External class folder - does not work - It looks weird to me to include whole this folder. My current project, I need little libraries, but it has whole libraries that I uses in other projects.
add builders with build.xml like Want an eclipse java project to run ant build files automatically - does not work neither.
How can I add this maven-ant libraries properly? Thanks for sharing your experiences and answers XD
=========== Extra Information ====================
This is my build.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project name="HibernateEx2" default="db" basedir="."
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="data.dir" value="data"/>
<artifact:dependencies pathId="dependency.classpath">
<dependency groupId="hsqldb" artifactId="hsqldb" version="1.8.0.10"/>
<dependency groupId="org.hibernate" artifactId="hibernate-core" version="4.3.10.Final">
<exclusion groupId="javax.transaction" artifactId="jta"/>
</dependency>
<!-- 3.2.4.GA - After hibernate4 need upgrade hibernate-tools -->
<dependency groupId="org.hibernate" artifactId="hibernate-tools" version="4.3.1.CR1"/>
<dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec" version="1.1.1"/>
<!-- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory -->
<dependency groupId="commons-logging" artifactId="commons-logging" version="1.2"/>
<dependency groupId="log4j" artifactId="log4j" version="1.2.17"/>
<!-- java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder -->
<dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.7.12"/>
</artifact:dependencies>
<path id="project.class.path">
<pathelement location="${class.root}"/>
<path refid="dependency.classpath" />
</path>
<!-- Explaining how to use hibernate -->
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="project.class.path"/>
<target name="db" description="Run HSQLDB database management UI against the database file -- use when application is not running">
<java classname="org.hsqldb.util.DatabaseManager" fork="yes">
<classpath refid="project.class.path"/>
<arg value="-driver"/>
<arg value="org.hsqldb.jdbcDriver"/>
<arg value="-url"/>
<arg value="jdbc:hsqldb:${data.dir}/music/"/>
<arg value="-user"/>
<arg value="sa"/>
</java>
</target>
<target name="print-classpath" description="Show the dependency class path">
<property name="class.path" refid="dependency.classpath"/>
<echo>${class.path}</echo>
</target>
<!-- Generate java code -->
<target name="codegen" description="Generate Java source from the OR mapping files">
<hibernatetool destdir="${source.root}">
<configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
<hbm2java/>
</hibernatetool>
</target>
<!-- Creating Sub drectories -->
<target name="prepare" description="Set up build structures">
<mkdir dir="${class.root}"/>
<copy todir="${class.root}">
<fileset dir="${source.root}">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
</fileset>
</copy>
</target>
<!-- Creating Schema for mapping files -->
<target name="schema" depends="prepare" description="Generate DB schema from the OR mappinf files">
<hibernatetool destdir="${source.root}">
<configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
<hbm2ddl drop="yes"/>
</hibernatetool>
</target>
<!-- Compile Java -->
<!-- added includeantruntime="false" to javac, since terminal compile warning -->
<target name="compile" depends="prepare">
<javac srcdir="${source.root}" destdir="${class.root}"
debug="on" optimize="off" deprecation="on" includeantruntime="false">
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="ctest" depends="compile">
<java classname="org.owls.ht.CreateTest" fork="true">
<classpath refid="project.class.path"/>
</java>
</target>
</project>
and This is what my project looks like.
src
-- source codes (includes hibernate.cfg.xml)
classes
-- compiled classes
data
-- logs and queries
build.xml
FYI, I am doing this with a book named [[Harness Hibernate]] written by James Elliot from O'reilly.
Thanks again b
For what you are trying to do, you need the filesetId and versionsId="dependency.versions" in your declaration of:
<artifact:dependencies filesetId="dependency.fileset" versionsId="dependency.versions"
Then add a copy task like so:
<copy todir="${lib.dir}">
<fileset refid="dependency.fileset" />
<mapper classpathref="maven-ant-tasks.classpath"
classname="org.apache.maven.artifact.ant.VersionMapper"
from="${dependency.versions}" to="flatten" />
</copy>
The to="flatten" will flaten your dependencies into a single folder, then you can include that folder on the classpath of eclipse project or wherever you need it.

Error while using Ant with Google App Engine on Java

I have a Google App Engine application written in Java that I'm trying to get set up to work with the Travis continuous integration server. As part of this process, I need to automate the build using ant (previously, I had just been using Eclipse).
In Google's documentation for App Engine, they have a complete ant buildfile for an App Engine project:
<project>
<property name="sdk.dir" location="../appengine-java-sdk" />
<import file="${sdk.dir}/config/user/ant-macros.xml" />
<path id="project.classpath">
<pathelement path="war/WEB-INF/classes" />
<fileset dir="war/WEB-INF/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="${sdk.dir}/lib">
<include name="shared/**/*.jar" />
</fileset>
</path>
<target name="copyjars"
description="Copies the App Engine JARs to the WAR.">
<copy
todir="war/WEB-INF/lib"
flatten="true">
<fileset dir="${sdk.dir}/lib/user">
<include name="**/*.jar" />
</fileset>
</copy>
</target>
<target name="compile" depends="copyjars"
description="Compiles Java source and copies other source files to the WAR.">
<mkdir dir="war/WEB-INF/classes" />
<copy todir="war/WEB-INF/classes">
<fileset dir="src">
<exclude name="**/*.java" />
</fileset>
</copy>
<javac
srcdir="src"
destdir="war/WEB-INF/classes"
classpathref="project.classpath"
debug="on" />
</target>
<target name="datanucleusenhance" depends="compile"
description="Performs JDO enhancement on compiled data classes.">
<enhance_war war="war" />
</target>
<target name="runserver" depends="datanucleusenhance"
description="Starts the development server.">
<dev_appserver war="war" />
</target>
<target name="update" depends="datanucleusenhance"
description="Uploads the application to App Engine.">
<appcfg action="update" war="war" />
</target>
<target name="update_indexes" depends="datanucleusenhance"
description="Uploads just the datastore index configuration to App Engine.">
<appcfg action="update_indexes" war="war" />
</target>
<target name="rollback" depends="datanucleusenhance"
description="Rolls back an interrupted application update.">
<appcfg action="rollback" war="war" />
</target>
<target name="request_logs"
description="Downloads log data from App Engine for the application.">
<appcfg action="request_logs" war="war">
<options>
<arg value="--num_days=5"/>
</options>
<args>
<arg value="logs.txt"/>
</args>
</appcfg>
</target>
</project>
I tried pasting this verbatum into the build.xml file for new app engine project generated using Eclipse, and running it (after copying the app engine sdk to the appropriate location, of course) but I'm getting the following error:
$ ant runserver
Buildfile: c:\Users\Ajedi32\Documents\Ajedi32\ant_test\build
xml
copyjars:
[copy] Copying 7 files to c:\Users\Ajedi32\Documents\Ajedi32\ant_test\war\WEB-INF\lib
compile:
[javac] c:\Users\Ajedi32\Documents\Ajedi32\ant_test\build.xml:39: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
datanucleusenhance:
[enhance] Encountered a problem: Unexpected exception
[enhance] Please see the logs [C:\Users\Ajedi32\AppData\Local\Temp\enhance5135186886756266241.log] for further information.
BUILD FAILED
c:\Users\Ajedi32\Documents\Ajedi32\ant_test\build.xml:44: The following error occurred while executing this line:
c:\Users\Ajedi32\Documents\Ajedi32\appengine-java-sdk-1.8.8\config\user\ant-macros.xml:95: Java returned: 1
Total time: 4 seconds
C:\Users\Ajedi32\AppData\Local\Temp\enhance5135186886756266241.log contains the following:
java.lang.RuntimeException: Unexpected exception
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:76)
at com.google.appengine.tools.enhancer.Enhance.<init>(Enhance.java:71)
at com.google.appengine.tools.enhancer.Enhance.main(Enhance.java:51)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.google.appengine.tools.enhancer.Enhancer.execute(Enhancer.java:74)
... 2 more
Caused by: java.lang.NoSuchMethodError: org.datanucleus.plugin.PluginManager.<init>(Lorg/datanucleus/PersistenceConfiguration;Lorg/datanucleus/ClassLoaderResolver;)V
at org.datanucleus.OMFContext.<init>(OMFContext.java:159)
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:172)
at org.datanucleus.enhancer.DataNucleusEnhancer.<init>(DataNucleusEnhancer.java:150)
at org.datanucleus.enhancer.DataNucleusEnhancer.main(DataNucleusEnhancer.java:1157)
... 7 more
What's gone wrong? Is Google's build.xml file wrong? I've literally never used ant before now, and I'm still pretty much a newbie with using Java and App Engine for production-quality applications so I'm totally lost here...
If anyone's ever set up App Engine to work with ant before, I'd really be interested in knowing how you did it. An example of an app engine application with a working ant build would be nice...

Run a ant scripts for a project that depends on other project

I am new for apache ant. Now, I am trying to run a single ant for two project. Lets see below....
I have a project named 'Multiply'. In that project, I write a java class named 'Multiply' and a function named 'multiply' that multiply two input integer and return result.
And then I created another project named 'Multiply-Test'. In build path configuration, I add 'Multiply' project into it to test. And then I write a Test class named 'MultiplyTest' and a test case that test return value of multiply function of Multiply class of Multiply Project.
And then I write a ant script (build.xml) file for 'Multiply-Test' project. My xml file is....
<!-- Sets variables which can later be used. -->
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="test.report.dir" location="test-result" />
<!-- Define the classpath which includes the junit.jar and the classes after compiling-->
<path id="junit.class.path">
<pathelement location="lib/junit.jar" />
<pathelement location="${build.dir}" />
</path>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${test.report.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${test.report.dir}" />
</target>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}/com/dat/multiply" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
</target>
<!-- Run the JUnit Tests -->
<target name="junit" depends="compile">
<junit printsummary="on" fork="true" haltonfailure="yes">
<classpath refid="junit.class.path" />
<formatter type="xml" />
<batchtest todir="${test.report.dir}">
<fileset dir="${src.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="main" depends="compile, junit">
<description>Main target</description>
</target>
And then I run ant script. I found the following error in console....
Buildfile: C:\Eclipse Kepler\workspace\Multiply-Test\build.xml
clean:
[delete] Deleting directory C:\Eclipse Kepler\workspace\Multiply-Test\bin
[delete] Deleting directory C:\Eclipse Kepler\workspace\Multiply-Test\test-tesult
makedir:
[mkdir] Created dir: C:\Eclipse Kepler\workspace\Multiply-Test\bin
[mkdir] Created dir: C:\Eclipse Kepler\workspace\Multiply-Test\test-result
compile:
[javac] C:\Eclipse Kepler\workspace\Multiply-Test\build.xml:29:
warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
junit:
[junit] Running com.dat.test.MultiplyTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
BUILD FAILED
C:\Eclipse Kepler\workspace\Multiply-Test\build.xml:36: Test com.dat.test.MultiplyTest failed
Total time: 1 second
And found the following junit output error......
java.lang.ClassNotFoundException: com.dat.test.MultiplyTest
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
But I test by another way. That, and then, I clean and build both project. And then run 'MultiplyTest' class by Right click on class -> Run As. -> JUnit Test. Oh, It is work really. And Junit result is true that i wish.
Now, I don't know how to do for work that test class from ant scripts. I need to solve, but I don't know.
Anybody help me. Thanks..!
This doesn't look right:
<javac srcdir="${src.dir}/com/dat/multiply" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>
The srcdir of <javac> shouldn't include the /com/dat/multiply part. The <javac> documentation explains:
Do not include part of your package structure in the srcdir attribute
Instead, it should be:
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="junit.class.path" />
</javac>

ANT build fails and gives classNotFoundExceeption in html report

After doing so many trial and errors on "How ANT tag works ?", I decided to write my own custom build xml file for the testcases that was written in Java and integrated with JUnit. Unfortunately my build script failing with "ClassNotFoundException". And i can see the log in generated HTML file that you get to see after running ant build script.
Please see below
<project name="WebServices integrated with JUnit and generating report with ANT" default="test" basedir="." >
<description> REST Services integration with JUnit </description>
<!-- set global properties for this build -->
<property name="project_name" value="junit"/>
<property name="src" location="src"/>
<property name="build" location="bin"/>
<property name="dist" location="dist"/>
<property name="lib" location="${user.home}/My Documents/Mr/jars"/>
<property name="reports" location="reports"/>
<!-- the names of various distributable files. NOTE: Generating distribution file "target" is not used here-->
<!-- Delete the ${build} and ${dist} directory trees -->
<target name="clean" description="clean up">
<delete dir="${build}"/>
<delete dir="${dist}"/>
<delete dir="${reports}"/>
</target>
<!-- Top level targets -->
<target name="compile" depends="init" description="compile the source code">
<javac srcdir="${src}" destdir="${build}">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- run your tests -->
<target name="run-tests" depends="compile" description="run your test suite">
<junit printsummary="yes" haltonfailure="no" showoutput="yes">
<classpath>
<pathelement path="${build}"/>
<fileset dir="${lib}">
<include name="**/*.jar"/>
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="${src}/Test/Services" >
<exclude name="MyFile.java"/>
<include name="**/*.java"/> // <------ IMP***: Here I am saying include .java files that are based at "${src}/Test/Services".
</fileset>
</batchtest>
</junit>
</target>
<!-- generate report on tests -->
<target name="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports}/html/"/>
</junitreport>
</target>
<target name="init" depends="clean" description="initialize the build envrionment">
<!--create the time stamp -->
<tstamp/>
<!-- Create directory structure -->
<mkdir dir="${build}"/> //<----dir for class files
<mkdir dir="${lib}"/> //<----dir for all my libraries
<mkdir dir="${dist}/lib"/> //<----not used
<mkdir dir="${reports}"/>
<mkdir dir="${reports}/raw/"/>
<mkdir dir="${reports}/html/"/> //<---- it will have output reports
</target>
<target name="all" depends="clean,test">
</target>
And I guessed ANT build will pick all the source files (.java) and then it will look for all the class files that are based in build folder and started running them, but then I see "classNotFoundException" in HTML report. please see below log :
CLASS : "getlieninfo"
> java.lang.ClassNotFoundException: getlieninfo
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
After a while I changed .java to .class in "include" tag of my target called "run-tests" . The reason for doing this is, I thought ANT is not able to look ".java" files in source folder (src/Test/Services) hence I changed to ".class" and then modified dir attribute value in "fileset" tag to "build" so it may easily look for ".class" in BUILD folder where I will have compiled files stored. But none of my trial and error succeeded and ended up with same "classNotFoundException".
I am not sure what went wrong , can someone help me, please?
OK guys, Thanks for what ever little help I got from you. I found the problem.
I had to change include tag attribute name to "name=/Test/Services/**/*.java"/>" and modify dir attribute in fileset tag to "${src}" ; see below :
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml"/>
<fileset dir="${src}" >
<exclude name="MyFile.java"/>
<include name="/Test/Services/**/*.java"/> //<----this where i had to modify.
NOTE: Under src directory I have Test/Services folder which has source ".java" files in it.
</fileset>
</batchtest>
It solved my problem, but then i don't understand why ant build was not able to identify source files when i gave dir attribute as dir="${src}/Test/Services" that is in fileset tag
and kept name attribute in include tag as name="**/*.java" . My understanding is fileset tag should build the path for for the given dir path , once the path is build include tag will include or look for mentioned source files i.e. ".java" .

Categories

Resources