Ant doesn't build second jar - java

I have an intellij project where I am trying to create 2 jars. I have setup my buildfile and run build ALL artifacts. However, only my FIRST jar comes up. To try to get more information I ran the command line command: ant -buildfile buildfile.xml
In the result I get the following:
artifact.jar1:jar:
[mkdir] Created dir: ~/Projects/proj1/__artifacts_temp/jar1_jar
[jar] Building jar: ~/Projects/proj1/__artifacts_temp/jar1.jar
[copy] Copying 1 file to ~/Projects/proj1/__artifacts_temp/jar1_jar
artifact.jar2:jar:
[mkdir] Created dir: ~/Projects/proj1/__artifacts_temp/jar2_jar
[jar] Building jar: ~/Projects/proj1/__artifacts_temp/1/jar2.jar
[copy] Copying 1 file to ~/Projects/proj1/__artifacts_temp/jar2_jar
So it looks like both jars will be created. However... the next output is more discouraging.
build.all.artifacts:
[copy] Copying 1 file to ~/Projects/proj1
[delete] Deleting directory ~/Projects/proj1/__artifacts_temp
I have absolutely no idea why it would only copy 1 of the jars back. Any thoughts or ideas on how to get more information would be greatly appreciated.
Edit:
Here is what the build.all.artifacts section of my build script looks like
<target name="build.all.artifacts" depends="artifact.jar1:jar, artifact.jar2:jar" description="Build all artifacts">
<mkdir dir="${artifact.output.jar1:jar}"/>
<copy todir="${artifact.output.jar1:jar}">
<fileset dir="${artifact.temp.output.jar1:jar}"/>
</copy>
<mkdir dir="${artifact.output.jar2:jar}"/>
<copy todir="${artifact.output.jar2:jar}">
<fileset dir="${artifact.temp.output.jar2:jar}"/>
</copy>
<!-- Delete temporary files -->
<delete dir="${artifacts.temp.dir}"/>
</target>

Check buildfile.xml, there should be a <copy> task for the first jar and not for the second.
Update: Try using <fileset dir="${artifact.temp.output.jar2:jar}" erroronmissingdir="true"/> to see if there's something wrong with the path.
Also try to print the paths to check if they are correct:
<echo>${artifact.output.jar2:jar}</echo>
<echo>${artifact.temp.output.jar2:jar}</echo>

Related

NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout Wrapping Problem Launch4j

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>

Build Android project on Eclipse with Ant

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

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....

Trouble running JUnit from Ant

Here's the target I'm using to run my tests:
<target name="run-tests" description="run the tests" depends="compilation">
<junit>
<sysproperty key="tests.basedir" value="${SPECIAL_PATH}/unit_tests"/>
<classpath>
<pathelement location="${COMPILED_CLASSES}"/>
<pathelement location="${basedir}/junit-4.8.1.jar"/>
</classpath>
<batchtest>
<fileset dir="${COMPILED_CLASSES}/unit_tests/">
<include name="**/Test*.class"/>
<exclude name="**/*$*"/>
</fileset>
</batchtest>
</junit>
</target>
However, every time I try to run this target, all my tests fail with something like:
[junit] java.lang.ClassNotFoundException: testpackage.TestMyClass
[junit] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
[junit] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:247)
The SPECIAL_PATH property points to the source code of the classes. The COMPILED_CLASSES property points to the place the .class files have been put. And I need the tests.basedir property because I use it from my unit tests.
What am I doing wrong?
EDIT:I also thought I should explain the exclude of the $. I'm excluding anonymous classes, because they don't represent TestCases, they're only used from them.
You are telling Junit to execute each test class in ${COMPILED_CLASSES}/unit_tests/ but you are putting just ${COMPILED_CLASSES} on the classpath. You probably need to change your classpath entry to
<pathelement location="${COMPILED_CLASSES}/unit_tests/"/>
Since your claspath has
${COMPILED_CLASSES}
and your test classes are in
${COMPILED_CLASSES}/unit_tests
they would need to be in package
unit_tests.<whatever the classpath is>
traditionally this is why people compile normal sources to target/classes and test sources to target/test-classes
You might need to compile the UnitTests. Could you post where you use the javac task?

Categories