Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

JAR Creation via Ant (Adding Individual Files)

0 views
Skip to first unread message

Jason Cavett

unread,
Nov 28, 2007, 7:43:54 PM11/28/07
to
I am attempting to use Ant to create a JAR file. So far, it works
using the (partial) code below.

<property name="build-name" value="Project" />
<property name="dist" value="dist/${build-name}" />
<property name="build" value="bin" />
<property name="resources" value="resources" />

<jar destfile="${dist}/${build-name}.jar" manifest="META-INF/
MANIFEST.MF" basedir="${build}" />


However, I need to now include a file found in ${resources} (an image
for my SplashScreen-Image), but I can't figure out how to get a hold
of it. I've tried using file, includes and various other tags that
along with the jar tag. But, I can't seem to get access.

Can anybody help? Thanks.

Roedy Green

unread,
Nov 28, 2007, 8:52:04 PM11/28/07
to
On Wed, 28 Nov 2007 16:43:54 -0800 (PST), Jason Cavett
<jason....@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>However, I need to now include a file found in ${resources} (an image
>for my SplashScreen-Image),

see http://mindprod.com/jgloss/ant.html
for sample scripts to include resources.

Jar files are built all in one step. You don't add to them. this is
especially true for signed jars. The whole point of signing its to
prevent later modifications.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Andrew Thompson

unread,
Nov 28, 2007, 8:58:59 PM11/28/07
to
Jason Cavett wrote:
>I am attempting to use Ant to create a JAR file.
..
>However, I need to now include ..

Whenever I find myself thinking that about resources
when dealing with Ant, I look direcly to a FileSet..
<http://ant.apache.org/manual/CoreTypes/fileset.html>

--
Andrew Thompson
http://www.physci.org/

Message posted via http://www.javakb.com

Arne Vajhøj

unread,
Nov 28, 2007, 9:14:15 PM11/28/07
to
Roedy Green wrote:
> Jar files are built all in one step. You don't add to them.

You most certainly can add to a jar file.

It is not used much, but it is possible.

> this is
> especially true for signed jars. The whole point of signing its to
> prevent later modifications.

That is true.

Arne

Jason Cavett

unread,
Nov 28, 2007, 9:48:56 PM11/28/07
to

Okay, that did help a lot - thank you. Now that I got the file inside
the JAR, I still can't seem to get the manifest (via SplashScreen-
Image) to find the file. What location is the file referenced from?
The top of the JAR (which is what I would suspect), the manifest,
something else?

Thanks again for your help.

Andrew Thompson

unread,
Nov 28, 2007, 10:25:58 PM11/28/07
to
Jason Cavett wrote:
>> >I am attempting to use Ant to create a JAR file.
(..with Splash)

>...Now that I got the file inside


>the JAR, I still can't seem to get the manifest (via SplashScreen-
>Image) to find the file. What location is the file referenced from?

I do not have direct experience with splashscreens, but
my understanding it that paths are referenced from the
root of the Jar, and accessed same as using getResource(String).

Did I remember correctly that your splash image name had a
space in it? Perhaps it needs to be correctly 'encoded'.

Are you including a Manifest you made? Or is Ant creating it?
I have had no end of trouble with self edited manifests, and
am quite happy to leave my (limited) needs in manifests to
be created via Ant as well.

Andrew Thompson

unread,
Nov 28, 2007, 10:32:29 PM11/28/07
to
Arne Vajhøj wrote:
>> Jar files are built all in one step. You don't add to them.
>
>You most certainly can add to a jar file.
>
>It is not used much, but it is possible.

It is especially handy when you need to include a lot
of resources (like classes) compressed, but other
resources such as images (that have their own - quite
efficient compression) as 'store' only - without compression.

For any large number of images(/resources), I would
generally split them into a separate Jar archive, but it
does become handy in this particular situation (where
the splash *has* to be in the same Jar as the classes).

Jason Cavett

unread,
Nov 29, 2007, 10:00:47 AM11/29/07
to
> Andrew Thompsonhttp://www.physci.org/
>
> Message posted viahttp://www.javakb.com

Okay, being referenced from the root of the JAR would make sense.

The name of my splash screen does have a space. That can easily be
remedied, though, so I'll remove the space and see if that helps.

How would using Ant to generate the manifests make it any better? (I
was actually thinking about reworking some of my ANT script
today...especially after reading the tutorial that Arne provided.
Having ANT generate the manifest wouldn't be a bad idea.)

Andrew Thompson

unread,
Nov 29, 2007, 4:44:25 PM11/29/07
to
Jason Cavett wrote:
..

>How would using Ant to generate the manifests make it any better?

1) Ant never forgets to include a single 'blank line' at the end of the
manifest
2) if spaces in names need to be encoded, it would probably do so
automatically
3) ..any one of a number of other reasons I could not be bothered looking
into
given I was convinced by '1)'

..


>Having ANT generate the manifest wouldn't be a bad idea.)

I think it's a f*cken great idea. Though I *might* be biased. ;)

Daniel Dyer

unread,
Nov 29, 2007, 5:10:07 PM11/29/07
to
On Thu, 29 Nov 2007 21:44:25 -0000, Andrew Thompson <u32984@uwe> wrote:

> Jason Cavett wrote:
> ..
>> How would using Ant to generate the manifests make it any better?
>
> 1) Ant never forgets to include a single 'blank line' at the end of the
> manifest
> 2) if spaces in names need to be encoded, it would probably do so
> automatically
> 3) ..any one of a number of other reasons I could not be bothered looking
> into
> given I was convinced by '1)'

Also, manifest line lengths must be no more than 72 characters and
continuation lines must start with a single space. Easier to let
something else (Ant) worry about that kind of nonsense.

Dan.

--
Daniel Dyer
http://www.uncommons.org

Jason Cavett

unread,
Nov 30, 2007, 11:17:35 AM11/30/07
to
On Nov 29, 4:44 pm, "Andrew Thompson" <u32984@uwe> wrote:
> Jason Cavett wrote:
>
> ..
>
> >How would using Ant to generate the manifests make it any better?
>
> 1) Ant never forgets to include a single 'blank line' at the end of the
> manifest
> 2) if spaces in names need to be encoded, it would probably do so
> automatically
> 3) ..any one of a number of other reasons I could not be bothered looking
> into
> given I was convinced by '1)'
>
> ..
>
> >Having ANT generate the manifest wouldn't be a bad idea.)
>
> I think it's a f*cken great idea. Though I *might* be biased. ;)
>
> --
> Andrew Thompsonhttp://www.physci.org/
>
> Message posted viahttp://www.javakb.com

You have convinced me. ;-)

:: goes off to make the manifest file via ANT ::

Andrew Thompson

unread,
Nov 30, 2007, 7:26:09 PM11/30/07
to
Jason Cavett wrote:

> ...especially after reading the tutorial that Arne provided.

BTW. Did you mean Roedy's page?
<http://mindprod.com/jgloss/ant.html>

I do not see any link from Arne in this thread.

--
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200711/1

0 new messages