ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <>
Subject RE: Accessing manifest information from within an ant build
Date Tue, 26 Nov 2002 16:52:24 GMT
I think this should answer your question ;-) --DD

PS: My longest and most complex JavaScript ever ;-)

P:\org_apache\antx>%ANT_HOME%\bin\ant -f jar-version-script.xml
Buildfile: jar-version-script.xml

   [script] C:\pro\jdk1.4\jre\lib\charsets.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jaws.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jce.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jsse.jar 1.4
   [script] C:\pro\jdk1.4\jre\lib\rt.jar 1.4.0
   [script] C:\pro\jdk1.4\jre\lib\sunrsasign.jar <not-found>

Total time: 1 second
P:\org_apache\antx>type jar-version-script.xml
<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
     Dominique Devienne <>     November 2002
<project name="jar-version" default="test">

  <target name="test">
    <fileset id="jars" dir="${java.home}/lib" includes="*.jar" />

    <!-- Iterate over the fileset, printing the filenames.
         Then attempt to open each file as a JAR, and read its manifest
         to extract the specification version, if any. -->
    <script language="javascript"><![CDATA[
      prj = self.getProject();
      jars = prj.getReference("jars");
      dir = new;
      filenames = jars.getDirectoryScanner(prj).getIncludedFiles();
      for (var i = 0; i < filenames.length; ++i) {
        file = new, filenames[i]);
        jar = new java.util.jar.JarFile(file);
        name = java.util.jar.Attributes.Name.IMPLEMENTATION_VERSION;
        version = jar.getManifest().getMainAttributes().getValue(name);
        version = (version == null)? "<not-found>": version;
        java.lang.System.out.println(file + " " + version);



-----Original Message-----
From: Frank Carver [] 
Sent: Saturday, November 23, 2002 2:47 AM
To: Ant Users List
Subject: RE: Accessing manifest information from within an ant build

Dominique Devienne <> said:

> I don't think so. Not directly. I'd define a fileset of your JARs, and
> a small JavaScript to look over it, and use JDK's
> import java.util.jar.*;
> new JarFile(filename).getManifest().getMainAttributes().getValue(
> Almost a one liner ;-) --DD

That looks neat.  Can you expand a little on the "look over it" part.  I
know to get the filenames out of a fileset like that, and a variation on
approach would be a great solution for a couple other problems which have
up on this list over the last few weeks.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message