Doubt in ant building

C

Chanchal

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
 
A

Alexey

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

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
 
A

Andrew Thompson

Alexey wrote:
...
...
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.

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

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

Martin Gregorie

Andrew said:
Alexey wrote:
..
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.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,127
Latest member
CyberDefense
Top