JAR Creation via Ant (Adding Individual Files)

J

Jason Cavett

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

Roedy Green

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

Arne Vajhøj

Roedy said:
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
 
J

Jason Cavett

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>

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

Andrew Thompson

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

Andrew Thompson

Arne said:
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).
 
J

Jason Cavett

(..with Splash)


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.

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

Andrew Thompson

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. ;)
 
D

Daniel Dyer

Jason Cavett wrote:
..

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

Jason Cavett

Jason Cavett wrote:

..


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)'

..


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

You have convinced me. ;-)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top