Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Building using Ant in Eclipse
Building using Ant in Eclipse [message #202598] Sun, 01 April 2007 03:24 Go to next message
Eclipse UserFriend
Originally posted by: jonathan.prater.gmail.com

I've written an Ant buildfile for my Eclipse project. Here is my target
from my buildfile that puts all my class files into a .JAR:
<target name="distro" depends="build">
<jar destfile="${dist-dir}/LMS.jar" basedir="${build-dir}">
<manifest>
<attribute name="Built-By" value="${user.name}"/>
<attribute name="Main-Class" value="com.jpprater.libmgr.LibMgrMainFrame"/>
<attribute name="Class-Path" value="${lib-dir}/*.jar
${basedir}/srv/hsqldb.jar"/>
</manifest>
</jar>
</target>
Very simple. ${build-dir} is directory that contains my class files
organized into packages after having been built. The manifest defines
the name of my main class, LibMgrMainFrame, in the package
com.jpprater.libmgr.
So, I run this target. It builds my class files and then jars them just
as I requested. I get a nice little jarfile that I then try to run.
Trying to run it gives me an error saying it can't find the main class.
I explore the jar file to verify that the main class is where it's
supposed to be, and it is. The only files in my jarfile are the ones
that should be there, but every time I try to run this thing, with or
without the main class explicitly defined on the java command line, I
get an error saying the main class could not be found. What gives?

Jon
Re: Building using Ant in Eclipse [message #202606 is a reply to message #202598] Sun, 01 April 2007 03:45 Go to previous messageGo to next message
Darin Swanson is currently offline Darin SwansonFriend
Messages: 2386
Registered: July 2009
Senior Member
Not an expert in this area...but don't you need an manifest file designating
the main class if you are attempting something like:
"java -jar x.jar".

HTH
Darins

"Jonathan Prater" <jonathan.prater@gmail.com> wrote in message
news:eun8m0$9rf$1@build.eclipse.org...
> I've written an Ant buildfile for my Eclipse project. Here is my target
> from my buildfile that puts all my class files into a .JAR:
> <target name="distro" depends="build">
> <jar destfile="${dist-dir}/LMS.jar" basedir="${build-dir}">
> <manifest>
> <attribute name="Built-By" value="${user.name}"/>
> <attribute name="Main-Class" value="com.jpprater.libmgr.LibMgrMainFrame"/>
> <attribute name="Class-Path" value="${lib-dir}/*.jar
> ${basedir}/srv/hsqldb.jar"/>
> </manifest>
> </jar>
> </target>
> Very simple. ${build-dir} is directory that contains my class files
> organized into packages after having been built. The manifest defines the
> name of my main class, LibMgrMainFrame, in the package
> com.jpprater.libmgr.
> So, I run this target. It builds my class files and then jars them just
> as I requested. I get a nice little jarfile that I then try to run.
> Trying to run it gives me an error saying it can't find the main class. I
> explore the jar file to verify that the main class is where it's supposed
> to be, and it is. The only files in my jarfile are the ones that should
> be there, but every time I try to run this thing, with or without the main
> class explicitly defined on the java command line, I get an error saying
> the main class could not be found. What gives?
>
> Jon
Re: Building using Ant in Eclipse [message #202627 is a reply to message #202606] Sun, 01 April 2007 12:50 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: jonathan.prater.gmail.com

If you look at the excerpt from my build file, there's a <manifest> tag
in there. The tags between <manifest></manifest> declare the content of
the manifest file, which Ant generates automatically.

Darin Swanson wrote:
> Not an expert in this area...but don't you need an manifest file designating
> the main class if you are attempting something like:
> "java -jar x.jar".
>
> HTH
> Darins
>
> "Jonathan Prater" <jonathan.prater@gmail.com> wrote in message
> news:eun8m0$9rf$1@build.eclipse.org...
>> I've written an Ant buildfile for my Eclipse project. Here is my target
>> from my buildfile that puts all my class files into a .JAR:
>> <target name="distro" depends="build">
>> <jar destfile="${dist-dir}/LMS.jar" basedir="${build-dir}">
>> <manifest>
>> <attribute name="Built-By" value="${user.name}"/>
>> <attribute name="Main-Class" value="com.jpprater.libmgr.LibMgrMainFrame"/>
>> <attribute name="Class-Path" value="${lib-dir}/*.jar
>> ${basedir}/srv/hsqldb.jar"/>
>> </manifest>
>> </jar>
>> </target>
>> Very simple. ${build-dir} is directory that contains my class files
>> organized into packages after having been built. The manifest defines the
>> name of my main class, LibMgrMainFrame, in the package
>> com.jpprater.libmgr.
>> So, I run this target. It builds my class files and then jars them just
>> as I requested. I get a nice little jarfile that I then try to run.
>> Trying to run it gives me an error saying it can't find the main class. I
>> explore the jar file to verify that the main class is where it's supposed
>> to be, and it is. The only files in my jarfile are the ones that should
>> be there, but every time I try to run this thing, with or without the main
>> class explicitly defined on the java command line, I get an error saying
>> the main class could not be found. What gives?
>>
>> Jon
>
>
Re: Building using Ant in Eclipse [message #202843 is a reply to message #202598] Mon, 02 April 2007 17:24 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse5.rizzoweb.com

Jonathan Prater wrote:
> I've written an Ant buildfile for my Eclipse project. Here is my target
> from my buildfile that puts all my class files into a .JAR:
> <target name="distro" depends="build">
> <jar destfile="${dist-dir}/LMS.jar" basedir="${build-dir}">
> <manifest>
> <attribute name="Built-By" value="${user.name}"/>
> <attribute name="Main-Class" value="com.jpprater.libmgr.LibMgrMainFrame"/>
> <attribute name="Class-Path" value="${lib-dir}/*.jar
> ${basedir}/srv/hsqldb.jar"/>
> </manifest>
> </jar>
> </target>
> Very simple. ${build-dir} is directory that contains my class files
> organized into packages after having been built. The manifest defines
> the name of my main class, LibMgrMainFrame, in the package
> com.jpprater.libmgr.
> So, I run this target. It builds my class files and then jars them just
> as I requested. I get a nice little jarfile that I then try to run.
> Trying to run it gives me an error saying it can't find the main class.
> I explore the jar file to verify that the main class is where it's
> supposed to be, and it is. The only files in my jarfile are the ones
> that should be there, but every time I try to run this thing, with or
> without the main class explicitly defined on the java command line, I
> get an error saying the main class could not be found. What gives?

Note that this is not really an Eclipse-specific question and should be
directed to a general Java or Any forum.
What are the contents of the manifest file in you JAR? Is it correctly
defining the main class that you expect? Are you certain the format of
that entry in the manifest is exactly correct (IIRC the JVM is picky
about the format of the manifest file)?

Hope this helps,
Eric
Previous Topic:Import User Libraries with a relative path
Next Topic:Recursive Debugging
Goto Forum:
  


Current Time: Fri Apr 19 03:22:13 GMT 2024

Powered by FUDForum. Page generated in 0.03999 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top