File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Determing the version of a jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Determing the version of a jar" Watch "Determing the version of a jar" New topic
Author

Determing the version of a jar

Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
I know you need to look at the manifest/manifestation file inside the jar but I've got to determine the version of ALL the jars on our servers and if I can I'd like to do it without downloading them all and unpacking them so I can read the files. Is there a command I can do at the command-line that will just return that information.
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
I don't know if there's an easy way to do it with the tools provided by the JDK but I don't think it'd be particularly difficult to write one in Java. Take a look at java.util.jar.JarFile which has a getManifest() method that will read and return the Manifest for a JAR file which you can in turn read Attributes from. Though I haven't done it I imagine it's rather trivial to grab what you're interested in and compile a file.

Of course, you'd have to actually find the JAR files to begin with. Though you should be able to specify a directory and recursively check each directory for any JAR files. I have no idea how long this would take.
Matt Kidd
Ranch Hand

Joined: Jul 17, 2002
Posts: 261
Thanks for the help. This worked but the problem is the inconsistency in actually completely filling out a Manifest for the JARs.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

a) * (later)
b) create a temp-Dir
c) create a script, to get the version:

d) find all jars in a directory, and execute your script:


a) find is integrated in GNU/Linux, and maybee in Solaris and MacOS too.
For MS, you have to download it: http://unxutils.sourceforge.net/
and use the full path, since MS has a find itself.

Output:
(...)
/opt/jdk1.5/jre/lib/ext/imap.jar
Created-By: Apache Ant 1.5.1
(...)
Created-By: Apache Ant 1.5.1beta1
/opt/jdk1.5/jre/lib/ext/commons-logging.jar
Created-By: 1.4.2_04-b05 (Sun Microsystems Inc.)
/opt/jdk1.5/jre/lib/ext/itext.jar
Created-By: Ant 1.4.1
(...)
/opt/jdk1.5/sample/jnlp/servlet/jnlp.jar
Created-By: 1.5.0_10 (Sun Microsystems Inc.)
/opt/jdk1.5/sample/jnlp/servlet/jnlp-servlet.jar
Created-By: 1.3.0_02 (Sun Microsystems Inc.)
/opt/jdk1.5/sample/jnlp/webpad/war/app/jhcore__V1.0.jar
Created-By: 1.2.2 (Sun Microsystems Inc.)
/opt/jdk1.5/sample/jnlp/webpad/war/app/jlfgr__V1.0.jar
Created-By: 1.2 (Sun Microsystems Inc.)
/opt/jdk1.5/sample/jnlp/webpad/war/app/holidays__V1.0.jar


Normally, directory are separated with backslash on MS, but after downloading the native win32 ports of some gnu-utils, you may use sh.exe.
Else you have to translate the jarver.sh
On MS, you need to fix your path yourself, or give the full path to grep.exe which isn't included in MS (but again in the gnu-utils).

Perhaps a grep and a better find are included in Vista.
[ March 05, 2007: Message edited by: Stefan Wagner ]

http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Determing the version of a jar