How to read MANIFEST.MF from program.

J

Jacob

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!
 
J

Jeffrey Palm

Jacob said:
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);
}
}
}
 
J

Jacob

Jeffrey said:
Jacob said:
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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top