//////////////////build.xml////////////////////////
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloWorldBuild" default="package">
<property name="outputDir" value="C:\newJava\" />
<property name="sourceDir" value="C:\java\sources\atreides\hello\" />
<target name="clean">
<delete dir="${outputDir}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${outputDir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${sourceDir}" destdir="${outputDir}" />
</target>
<target name="package" depends="compile">
<jar jarfile="${outputDir}\HelloWorldGui.jar"
basedir="${outputDir}" />
</target>
</project>
thanks,
Thufir Hawat
But if you already have a manifest file that you anly want to add this line,
specify append="true".
And then specify that you want to use that manifest file while creating your
jar:
<jar jarfile="${outputDir}\HelloWorldGui.jar" basedir="${outputDir}"
manifest="<somewhere>/MANIFEST.MF"/>
This should to do what you need
Jacques Desmazieres
"thufir" <thufir...@mail.com> a écrit dans le message de news:
1106556162.4...@z14g2000cwz.googlegroups.com...
Add this target:
<target name="manifest" depends="prepare">
<manifest file="$(outputDir}/MANIFEST.MF">
<attribute name="Main-Class" value="HelloWorldGui" />
</manifest>
</target>
Add the "manifest" attribute to your "package" target with this:
<target name="package" depends="compile,manifest">
<jar jarfile="${outputDir}/HelloWorldGui.jar" basedir="${outputDir}"
manifest="${outputDir}/MANIFEST.MF" />
</target>
See:
<http://ant.apache.org/manual/CoreTasks/manifest.html>
Chas Douglass
///////command line/////////////////////
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\>ant
Buildfile: build.xml
clean:
[delete] Deleting directory C:\newJava
prepare:
[mkdir] Created dir: C:\newJava
compile:
[javac] Compiling 1 source file to C:\newJava
manifest:
BUILD FAILED
C:\build.xml:23: Failed to write C:\$(outputDir}\MANIFEST.MF
Total time: 4 seconds
C:\>type build.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloWorldSwing" default="package">
<property name="outputDir" value="C:\newJava\" />
<property name="sourceDir"
value="C:\java\sources\atreides\hello\" />
<property name="jarName" value="HelloWorldSwing" />
<target name="clean">
<delete dir="${outputDir}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${outputDir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${sourceDir}" destdir="${outputDir}" />
</target>
<target name="manifest" depends="compile">
<manifest file="$(outputDir}/MANIFEST.MF">
<attribute name="Main-Class" value="${jarName}"
/>
</manifest>
</target>
<target name="package" depends="manifest">
<jar jarfile="${outputDir}/${jarName}"
basedir="${outputDir}"
manifest="${outputDir}/MANIFEST.MF" />
</target>
</project>
C:\>
C:\>
C:\>
thanks,
Thufir Hawat
> build.xml looks fine to me, but it chokes on the manifest for some
> reason. Why, please?
>
I'm using Ant 1.6.2. Are you?
Chas Douglass
///////////command line//////////////////
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\>ant -version
Apache Ant version 1.6.2 compiled on July 16 2004
C:\>type build.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloWorldBuild" default="package">
</project>
C:\>ant
Buildfile: build.xml
clean:
[delete] Deleting directory C:\newJava
prepare:
[mkdir] Created dir: C:\newJava
compile:
[javac] Compiling 1 source file to C:\newJava
manifest:
BUILD FAILED
C:\build.xml:23: Failed to write C:\$(outputDir}\MANIFEST.MF
Total time: 4 seconds
C:\>
thanks,
Thufir Hawat
> manifest:
>
> BUILD FAILED
> C:\build.xml:23: Failed to write C:\$(outputDir}\MANIFEST.MF
> Total time: 4 seconds
> C:\>
You have a left paren "(" instead of a left curly brace "{" on your
"${outputDir}".
Chas Douglass
It seems that ant's now creating the jar, but there's something wrong,
and I'm not sure where. The source comes directly from Suns' tutorial,
which I've previously compiled and ran with no problems. It seems to
be a problem with the names in the jar?
//////command line////////////
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.
C:\>ant
Buildfile: build.xml
clean:
[delete] Deleting directory C:\java\classes
prepare:
[mkdir] Created dir: C:\java\classes
compile:
[javac] Compiling 1 source file to C:\java\classes
manifest:
package:
[jar] Building jar: C:\java\classes\HelloWorldSwing.jar
BUILD SUCCESSFUL
Total time: 4 seconds
C:\>type build.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="HelloWorldBuild" default="package">
<property name="outputDir" value="C:\java\classes\" />
<property name="sourceDir"
value="C:\java\sources\atreides\hello\" />
<property name="jarName" value="HelloWorldSwing" />
<target name="clean">
<delete dir="${outputDir}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${outputDir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${sourceDir}" destdir="${outputDir}" />
</target>
<target name="manifest" depends="compile">
<manifest file="${outputDir}/MANIFEST.MF">
<attribute name="Main-Class" value="${jarName}"
/>
</manifest>
</target>
<target name="package" depends="manifest">
<jar jarfile="${outputDir}/${jarName}.jar"
basedir="${outputDir}"
manifest="${outputDir}/MANIFEST.MF" />
</target>
</project>
C:\>cd java\classes
C:\java\classes>dir
Volume in drive C has no label.
Volume Serial Number is B4B8-3B46
Directory of C:\java\classes
01/25/2005 01:42p <DIR> .
01/25/2005 01:42p <DIR> ..
01/25/2005 01:42p <DIR> atreides
01/25/2005 01:42p 1,906 HelloWorldSwing.jar
01/25/2005 01:42p 135 MANIFEST.MF
2 File(s) 2,041 bytes
3 Dir(s) 4,248,195,072 bytes free
C:\java\classes>jar -tvf HelloWorldSwing.jar
0 Tue Jan 25 13:42:34 PST 2005 META-INF/
135 Tue Jan 25 13:42:32 PST 2005 META-INF/MANIFEST.MF
135 Tue Jan 25 13:42:34 PST 2005 MANIFEST.MF
0 Tue Jan 25 13:42:34 PST 2005 atreides/
0 Tue Jan 25 13:42:34 PST 2005 atreides/hello/
367 Tue Jan 25 13:42:34 PST 2005
atreides/hello/HelloWorldSwing$1.class
915 Tue Jan 25 13:42:34 PST 2005
atreides/hello/HelloWorldSwing.class
C:\java\classes>java -jar HelloWorldSwing.jar
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing
C:\java\classes>cd atreides\hello
C:\java\classes\atreides\hello>dir
Volume in drive C has no label.
Volume Serial Number is B4B8-3B46
Directory of C:\java\classes\atreides\hello
01/25/2005 01:42p <DIR> .
01/25/2005 01:42p <DIR> ..
01/25/2005 01:42p 367 HelloWorldSwing$1.class
01/25/2005 01:42p 915 HelloWorldSwing.class
2 File(s) 1,282 bytes
2 Dir(s) 4,248,174,592 bytes free
2 Dir(s) 4,248,174,592 bytes free
C:\java\classes\atreides\hello>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError:
HelloWorldSwing
(wrong name: atreides/hello/HelloWorldSwing)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(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.ClassLoader.loadClassInternal(Unknown Source)
C:\java\classes\atreides\hello>
thanks,
Thufir Hawat