Ant, jar files and names libraries

Hi,

I want to accomplish the following...

I want a jar file that I can double-click in windows so it will run on its
own.
I am using the Xerces and Xalan library in my project.

So far I can compile the project in idea and compile and create a jar file
with ant in idea.
If I copy the classes in the xalan and xerces library jar files (manually)
to my project jar file and set the jar
file association in windows then I have what I want. But of course I would
like to do this automatically somehow
in idea with ant.

The first question I have is how I reference my idea named libraries in the
ant script and copy classes from it?

Is there some other way to create the jar file without copying the classes?
Can I copy jar files in jar files and
get the same result somehow?

And finally... is there some way that only the imported/needed classes are
copied automatically?

Thanks for any help.

Robert.


4 comments
Comment actions Permalink

Robert wrote:

Is there some other way to create the jar file without copying the classes?
Can I copy jar files in jar files and
get the same result somehow?


Add a manifest file to your jar. In the manifest file, add a ClassPath
attribute which references the xerces and xalan jars, like so:

Manifest-Version: 1.0
Class-Path: xerces.jar xalan.jar

You can use relative paths which are resolved relative to the location
of your jar.

You can do this in ant using the manifest element in a jar element:

You can also include the contents of another zip/jar file when building a jar file in ant using the zipgroupfileset element. Ciao, Gordon -- Gordon Tyler (Software Developer) Quest Software ]]>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0
Comment actions Permalink

Gordon Tyler wrote:

Robert wrote:

Is there some other way to create the jar file without copying the

classes?

Can I copy jar files in jar files and
get the same result somehow?

>

You can also include the contents of another zip/jar file when building
a jar file in ant using the zipgroupfileset element.


Okay, the zipgroupfileset really helped.
Now all I need to know is how I can reference my named library jar file in
the ant script.
Do you know how to do this?


0
Comment actions Permalink

Robert wrote:

Okay, the zipgroupfileset really helped.
Now all I need to know is how I can reference my named library jar file in
the ant script.
Do you know how to do this?


All I can suggest is that you place the library jars in a known
location, preferably relative to your project. For example:

MyProject/
build.xml
build/
classes/
dist/
src/
java/
com/
acme/
...
lib/
xalan.jar
xerces.jar

With this project structure, your build.xml compiles in
MyProject/build/classes and then builds your jar in
MyProject/build/dist/lib, pulling in the contents of xalan.jar and
xerces.jar from MyProject/lib.

Ciao,
Gordon

--
Gordon Tyler (Software Developer)
Quest Software <http://java.quest.com/>
260 King Street East, Toronto, Ontario M5A 4L5, Canada
Voice: 416-643-4846 | Fax: 416-594-1919

0
Comment actions Permalink

Gordon Tyler wrote:

Robert wrote:

Okay, the zipgroupfileset really helped.
Now all I need to know is how I can reference my named library jar file

in

the ant script.
Do you know how to do this?

>

All I can suggest is that you place the library jars in a known
location, preferably relative to your project. For example:

>

MyProject/
lib/
xalan.jar
xerces.jar

>

With this project structure, your build.xml compiles in
MyProject/build/classes and then builds your jar in
MyProject/build/dist/lib, pulling in the contents of xalan.jar and
xerces.jar from MyProject/lib.


Ohh hmmmm. I'm afraid that it is not really practical in my case.
We are using CVS and decided not to store 3rd party libraries in CVS.
It also would be rather much to store these libraries per project.

When I compile with ant it all works fine. So ant must have been able to
locate the xalan and xerces jar files (that were referenced in the idea
project file).
I was hoping for something like $(xalan-j_2_5_1.home) I could use.


0

Please sign in to leave a comment.