You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ray Tayek <rt...@attbi.com> on 2002/03/04 02:56:31 UTC

Failed to load Main-Class manifest from foo.jar

hi, i used the following sample ant script (copied from the doc) to build a 
jar. but when i try to run it using java -jar foo.jar, i get the above 
error message. i looked at the jar and the manifest has no files in it. is 
this a bug in ant? or do i need to invoke the jar in some different manner? 
or build the manifest myself? i am using ant 1.4.1 with j2sdk1.4.0

thanks

<project name="MyProject" default="dist" basedir=".">

   <!-- set global properties for this build -->
   <property name="src" value="."/>
   <property name="build" value="build"/>
   <property name="dist"  value="dist"/>

   <target name="init">
     <!-- Create the time stamp -->
     <tstamp/>
     <!-- Create the build directory structure used by compile -->
     <mkdir dir="${build}"/>
   </target>

   <target name="compile" depends="init">
     <!-- Compile the java code from ${src} into ${build} -->
     <javac srcdir="${src}" destdir="${build}"/>
   </target>

   <target name="dist" depends="compile">
     <!-- Create the distribution directory -->
     <mkdir dir="${dist}/lib"/>

     <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
     <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
   </target>

   <target name="clean">
     <!-- Delete the ${build} and ${dist} directory trees -->
     <delete dir="${build}"/>
     <delete dir="${dist}"/>
   </target>
</project>

---
ray tayek http://home.earthlink.net/~rtayek/
actively seeking telecommuting work
orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Failed to load Main-Class manifest from foo.jar

Posted by Ray Tayek <rt...@attbi.com>.
At 01:04 PM 3/4/02 +1100, you wrote:
>...You need to construct the manifest yourself. In general, Ant can't know
>which class is to be the main class....
>
>     <jar basedir="${bin.dir}/start" jarfile="${distlib.dir}/start.jar">
>       <manifest>
>         <attribute name="Main-Class" value="org.apache.ant.start.Main"/>
>       </manifest>
>     </jar>
>...
>http://jakarta.apache.org/ant/manual/CoreTasks/jar.html

works great now!

thanks

---
ray tayek http://home.earthlink.net/~rtayek/
actively seeking telecommuting work
orange county java users group http://www.ocjug.org/
hate spam? http://samspade.org/ssw/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Failed to load Main-Class manifest from foo.jar

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Ray,

You need to construct the manifest yourself. In general, Ant can't know
which class is to be the main class. You need to specify this in the
manifest using the Main-Class header. Here is an example where you specify
the Main-Class in the build file

    <jar basedir="${bin.dir}/start" jarfile="${distlib.dir}/start.jar">
      <manifest>
        <attribute name="Main-Class" value="org.apache.ant.start.Main"/>
      </manifest>
    </jar>

Alternatively you can create a manifest file and use that in the <jar> task.
Checkout the documentation

http://jakarta.apache.org/ant/manual/CoreTasks/jar.html

Conor

> -----Original Message-----
> From: Ray Tayek [mailto:rtayek@attbi.com]
> Sent: Monday, 4 March 2002 12:57 PM
> To: ant-user@jakarta.apache.org
> Subject: Failed to load Main-Class manifest from foo.jar
>
>
> hi, i used the following sample ant script (copied from the doc)
> to build a
> jar. but when i try to run it using java -jar foo.jar, i get the above
> error message. i looked at the jar and the manifest has no files
> in it. is
> this a bug in ant? or do i need to invoke the jar in some
> different manner?
> or build the manifest myself? i am using ant 1.4.1 with j2sdk1.4.0
>
> thanks
>
> <project name="MyProject" default="dist" basedir=".">
>
>    <!-- set global properties for this build -->
>    <property name="src" value="."/>
>    <property name="build" value="build"/>
>    <property name="dist"  value="dist"/>
>
>    <target name="init">
>      <!-- Create the time stamp -->
>      <tstamp/>
>      <!-- Create the build directory structure used by compile -->
>      <mkdir dir="${build}"/>
>    </target>
>
>    <target name="compile" depends="init">
>      <!-- Compile the java code from ${src} into ${build} -->
>      <javac srcdir="${src}" destdir="${build}"/>
>    </target>
>
>    <target name="dist" depends="compile">
>      <!-- Create the distribution directory -->
>      <mkdir dir="${dist}/lib"/>
>
>      <!-- Put everything in ${build} into the
> MyProject-${DSTAMP}.jar file -->
>      <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"
> basedir="${build}"/>
>    </target>
>
>    <target name="clean">
>      <!-- Delete the ${build} and ${dist} directory trees -->
>      <delete dir="${build}"/>
>      <delete dir="${dist}"/>
>    </target>
> </project>
>
> ---
> ray tayek http://home.earthlink.net/~rtayek/
> actively seeking telecommuting work
> orange county java users group http://www.ocjug.org/
> hate spam? http://samspade.org/ssw/
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Failed to load Main-Class manifest from foo.jar

Posted by Friek <er...@sumerduckva.com>.
You haven't made a manifest, so Java doesn't know which class to load from
the jar first.

Grok the Sun docs for how manifest files work
(http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html), then
use <manifest> elements to define manifest properties in the <jar> tag.

> jar. but when i try to run it using java -jar foo.jar, i get the above
> error message. i looked at the jar and the manifest has no files
> in it. is
> this a bug in ant? or do i need to invoke the jar in some
> different manner?
> or build the manifest myself? i am using ant 1.4.1 with j2sdk1.4.0


>      <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar"
> basedir="${build}"/>
>    </target>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>