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 / November 2007

Tip: Looking for answers? Try searching our database.

Doubt in ant building

Thread view: 
Chanchal - 02 Nov 2007 14:16 GMT
Hi All,
i'm a newbie to Ant. i'm trying to create jar file using ant. this
will contain java classes and some other jar files.how can i specify
that jars which will be bundled into the created jar file should be in
classpath when the java class in the the created jar file is run?

it'll be really helpful if someone can give me a sample build.xml file
doing this.

thanks in advance

Chanchal
Alexey - 02 Nov 2007 16:57 GMT
> Hi All,
> i'm a newbie to Ant. i'm trying to create jar file using ant. this
[quoted text clipped - 8 lines]
>
> Chanchal

You have 2 options: you can either form a single jar out of all the
external jar's you're using (unzip/unjar them and then jar everything
into a single jar file).  I use this technique in bundling BeanShell
classes in an open source project of mine.  The build file can be seen
here: http://tinyurl.com/yodb9f

The other option is to specify class path information in your jar's
manifest file.  Here's some specification information relating to
this: http://tinyurl.com/2592f8
Andrew Thompson - 02 Nov 2007 17:35 GMT
...
>> i'm a newbie to Ant. i'm trying to create jar file using ant.
...
>You have 2 options: you can either form a single jar ..
...
>The other option is to specify class path information in your jar's
>manifest file.  ...

There is at least one more option.  If the app. is to be
launched by web start, the 'option 2' listed above will
not work.  Instead, the deployer could reference the
extra jars from the JNLP file.

Note to the OP.  The word "I" and abbreviation "I'm"
should always start with a Capital Letter.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Martin Gregorie - 02 Nov 2007 18:29 GMT
> ..
>>> i'm a newbie to Ant. i'm trying to create jar file using ant.
[quoted text clipped - 3 lines]
>> The other option is to specify class path information in your jar's
>> manifest file.  ...

Note that:

"The Class-Path header points to classes or JAR files on the local
network, not JAR files within the JAR file or classes accessible over
internet protocols. To load classes in JAR files within a JAR file into
the class path, you must write custom code to load those classes. For
example, if MyJar.jar contains another JAR file called MyUtils.jar, you
cannot use the Class-Path header in MyJar.jar's manifest to load classes
in MyUtils.jar into the class path."

- from "Adding Classes to the JAR File's Classpath" in the JAR Files
trail in the Java Tutorial.

IOW if you want to leave the packaged jar files on your jar file you'll
have to write a custom class loader, though that may not be very
difficult. However, the simple approach would be to put the other jar
files in the same directory as your jar file and zip the lot for
distribution. Your manifest then merely lists the other jar files and
installation consists of unzipping the archive some place and adjusting
the destination host's class path as needed.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
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.