Skip to content

Instantly share code, notes, and snippets.

@ebridges
Created April 25, 2013 02:30
Show Gist options
  • Save ebridges/5457090 to your computer and use it in GitHub Desktop.
Save ebridges/5457090 to your computer and use it in GitHub Desktop.
Given a jar file, extract out the `pom.properties` and create a java.util.Properties object from it.
import java.io.*;
import java.util.*;
import java.util.jar.*;
public class JarList
{
public static void main (String args[]) throws IOException
{
if (args.length != 1)
{
System.out.println("Please provide a JAR filename");
System.exit(-1);
}
JarFile jarFile = new JarFile(args[0]);
Enumeration enu = jarFile.entries();
while (enu.hasMoreElements())
process(jarFile, enu.nextElement());
}
private static void process(JarFile jarFile, Object obj) throws IOException
{
JarEntry entry = (JarEntry)obj;
String name = entry.getName();
if(name.endsWith("pom.properties")) {
InputStream is = jarFile.getInputStream(entry);
Properties p = new Properties();
p.load(is);
String g = p.getProperty("groupId");
String a = p.getProperty("artifactId");
String v = p.getProperty("version");
System.out.println(g+":"+a+":"+v);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment