How to read MANIFEST.MF from program.

Discussion in 'Java' started by Jacob, Dec 10, 2003.

  1. Jacob

    Jacob Guest

    I do:

    getClass().getResourceAsStream ("/META-INF/MANIFEST.MF");

    but instead of getting "my" manifest file, I get the
    one from rt.jar which is first (I assume) in the classpath.

    How can I access the MANIFEST.MF of the jar from which I
    am doing the call?

    Thanks!
    Jacob, Dec 10, 2003
    #1
    1. Advertising

  2. Jacob

    Jeffrey Palm Guest

    Jacob wrote:
    > I do:
    >
    > getClass().getResourceAsStream ("/META-INF/MANIFEST.MF");
    >
    > but instead of getting "my" manifest file, I get the
    > one from rt.jar which is first (I assume) in the classpath.
    >
    > How can I access the MANIFEST.MF of the jar from which I
    > am doing the call?
    >
    > Thanks!
    >


    try this:

    import java.io.*;
    import java.util.*;
    import java.util.jar.*;

    public class Jacob {
    public static void main(String[] args) throws Exception {
    final String JARFILE = args.length == 0 ? "c.jar" : args[0];
    final String classpath = System.getProperty("java.class.path");
    final String pathsep = System.getProperty("path.separator");
    for (StringTokenizer t = new StringTokenizer(classpath, pathsep,
    false);
    t.hasMoreTokens();) {
    String path = t.nextToken();
    if (!path.endsWith(JARFILE)) continue;
    JarFile jf = new JarFile(path);
    Manifest m = jf.getManifest();
    System.out.println(m);
    }
    }
    }

    --
    Jeffrey Palm --> http://www.ccs.neu.edu/home/jpalm
    Jeffrey Palm, Dec 10, 2003
    #2
    1. Advertising

  3. Jacob

    Jacob Guest

    Jeffrey Palm wrote:
    > Jacob wrote:
    >
    >> I do:
    >>
    >> getClass().getResourceAsStream ("/META-INF/MANIFEST.MF");
    >>
    >> but instead of getting "my" manifest file, I get the
    >> one from rt.jar which is first (I assume) in the classpath.
    >>
    >> How can I access the MANIFEST.MF of the jar from which I
    >> am doing the call?
    >>
    >> Thanks!
    >>

    >
    > try this:
    >
    > import java.io.*;
    > import java.util.*;
    > import java.util.jar.*;
    >
    > public class Jacob {
    > public static void main(String[] args) throws Exception {
    > final String JARFILE = args.length == 0 ? "c.jar" : args[0];
    > final String classpath = System.getProperty("java.class.path");
    > final String pathsep = System.getProperty("path.separator");
    > for (StringTokenizer t = new StringTokenizer(classpath, pathsep,
    > false);
    > t.hasMoreTokens();) {
    > String path = t.nextToken();
    > if (!path.endsWith(JARFILE)) continue;
    > JarFile jf = new JarFile(path);
    > Manifest m = jf.getManifest();
    > System.out.println(m);
    > }
    > }
    > }
    >


    Thanks!

    But it doesn't work when running through Java Web Start.
    Then it seems like javaws-l10n.jar is the only jar that
    appears in "java.class.path".

    Any other solutions?

    Thanks!
    Jacob, Dec 12, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RyanC
    Replies:
    2
    Views:
    4,026
    Oscar Kind
    Jan 23, 2004
  2. Albrecht Scheidig

    SOLVED: How to read MANIFEST.MF from plugin

    Albrecht Scheidig, Feb 12, 2004, in forum: Java
    Replies:
    0
    Views:
    2,429
    Albrecht Scheidig
    Feb 12, 2004
  3. Replies:
    3
    Views:
    514
    John W. Krahn
    Apr 7, 2006
  4. Replies:
    2
    Views:
    1,164
  5. Replies:
    3
    Views:
    158
    John W. Krahn
    Apr 7, 2006
Loading...

Share This Page