Skip to content

Instantly share code, notes, and snippets.

@ebridges
Created April 25, 2013 02:30
Show Gist options
  • Select an option

  • Save ebridges/5457090 to your computer and use it in GitHub Desktop.

Select an option

Save ebridges/5457090 to your computer and use it in GitHub Desktop.

Revisions

  1. ebridges created this gist Apr 25, 2013.
    34 changes: 34 additions & 0 deletions JarList.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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);
    }
    }
    }