Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2007

Tip: Looking for answers? Try searching our database.

JAR Creation via Ant (Adding Individual Files)

Thread view: 
Jason Cavett - 29 Nov 2007 00:43 GMT
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 - 29 Nov 2007 01:52 GMT
On Wed, 28 Nov 2007 16:43:54 -0800 (PST), Jason Cavett
<jason.cavett@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.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Arne Vajhøj - 29 Nov 2007 02:14 GMT
> 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
Andrew Thompson - 29 Nov 2007 03:32 GMT
>> 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).

Signature

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

Andrew Thompson - 29 Nov 2007 01:58 GMT
>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>

Signature

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

Jason Cavett - 29 Nov 2007 02:48 GMT
> >I am attempting to use Ant to create a JAR file.
> ..
[quoted text clipped - 8 lines]
>
> Message posted viahttp://www.javakb.com

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 - 29 Nov 2007 03:25 GMT
>> >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.

Signature

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

Jason Cavett - 29 Nov 2007 15:00 GMT
> >> >I am attempting to use Ant to create a JAR file.
>
[quoted text clipped - 20 lines]
>
> 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 - 29 Nov 2007 21:44 GMT
...
>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.  ;)

Signature

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

Daniel Dyer - 29 Nov 2007 22:10 GMT
> ..
>> How would using Ant to generate the manifests make it any better?
[quoted text clipped - 6 lines]
> 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.

Signature

Daniel Dyer
http://www.uncommons.org

Jason Cavett - 30 Nov 2007 16:17 GMT
> ..
>
[quoted text clipped - 18 lines]
>
> Message posted viahttp://www.javakb.com

You have convinced me.  ;-)

:: goes off to make the manifest file via ANT ::
Andrew Thompson - 01 Dec 2007 00:26 GMT
> ...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.

Signature

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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.