How to load the original manifest file

Hi I wrote an application. Is lanunched by webstart.

In the original jar file is set an property like a Program-version:1.5

after launching the application I can fread resources from "/resources/images/myimage", but I Cant read the from the manifest file.

just 2 properties: Manifest version and oanother one.

What can I do?

[355 byte] By [matheszabia] at [2007-11-26 13:02:41]
# 1
> ...> What can I do? Use util.jar.JarFile.getManifest()(etcetera..)
AndrewThompson64a at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...
# 2

Hi the original jar amifest file content is:

Manifest-Version: 1.0

Program-Version: 0.1

Java-Version-jar: 1.6.0

Java-Target: 1.5

Ant-Version: Apache Ant version 1.6.5 compiled on June 2 2005

Build-Number: 46

Class-Path:

Built-By: Mathe Szabolcs at December 20 2006

Created-By: 1.6.0-b105 (Sun Microsystems Inc.)

Main-Class: my.full.package.MyMain

...

folowed by the signed jar rows:

Name: ....

SHA1-Digest: : .....

The manifest file is located on thze jar file /META-INF/MANIFEST.MF whitch is signed.

Atfer that I put it on the webserver, and I a lunched with webstart

In the application mainframe (extended JFame) I load an image for a label:

lbLlogo.setIcon(new ImageIcon(getClass().getResource("/resources/images/logo.png")));

The image loaded and displayed correctly.

After that I want to read the manifest file:

URL url = getClass().getResource("/META-INF/MANIFEST.MF");

.... some checkings ...

BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));

String line = br.readLine();

String programVersion = null; // need to get from manifest

String buildNumber = null;// need to get from manifest

while (((programVersion == null) || (buildNumber == null)) && (line != null)){

.... checkings...

System.out.println("DEBUG: " +i+". line = " + line);

line = br.readLine();

}

...

The output with webstart is :

DEBUG: 1. line = Manifest-Version: 1.0

DEBUG: 2. line = Created-By: 1.6.0 (Sun Microsystems Inc.)

DEBUG: 3. line =

DEBUG: 4. line =

DEBUG: 5. line =

DEBUG: 6. line =

DEBUG: 7. line =

DEBUG: 8. line =

DEBUG: 9. line =

DEBUG: 10. line =

The output by launching the jar (java -jar myApplication.jar) is:

DEBUG: 1. line = Manifest-Version: 1.0

DEBUG: 2. line = Program-Version: 0.1

DEBUG: 3. line = Java-Version-jar: 1.6.0

DEBUG: 4. line = Java-Target: 1.5

DEBUG: 5. line = Ant-Version: Apache Ant version 1.6.5 compiled on June 2 2005

DEBUG: 6. line = Build-Number: 46

What's wrong? Why does nou match the 2 output. How can I make to be the same?

Szabi

matheszabia at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...
# 3

> What's wrong?

I could make some (sarcastic) suggestions

based on your apparent lack of experience

with with Java, or at least basic debugging

techniques..

> Why does nou match the 2 output.

> How can I make to be the same?

To begin to find out what is happening, change

your code as follows.....

//lbLlogo.setIcon(new ImageIcon(getClass().

//getResource("/resources/images/logo.png")));

URL urlTemp = getClass().

getResource("/resources/images/logo.png");

System.out.println(urlTemp);

lbLlogo.setIcon(new ImageIcon(urlTemp));

.....

// The image loaded and displayed correctly.

// After that I want to read the manifest file:

URL url = getClass().getResource("/META-INF/MANIFEST.MF");

//.... some checkings ... STARTING WITH

System.out.println(url);

....

AndrewThompson64a at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...
# 4

Hi AndrewThompson64 !

You have right!

Image url = jar:http://www.theWebServer.com/file/path/myApplication.jar!/resources/images/logo.png

Manifest url = jar:file:/C:/Program%20Files/Java/jre1.6.0/lib/javaws.jar!/META-INF/MANIFEST.MF

Is not the same! :-))

It is true: The first time when I want to read the manifest file. And I never imagene before: I read my application image, and I cant read the same manifest :-))

But if in my main static method if I call:

Thread.currentThread().getContextClassLoader().getResource("/resources/images/logo.png")

this URL is null !!

Why?

I know I should learn something about classloaders, but when is changed the jnlp loader to a "normal" classloader. when I launch only the .jar file I have no problems, but I need webstart! :-)

Szabi

matheszabia at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...
# 5

> You have right!

That is one of the advantanges of saying a lot

of things - I am regularly wrong, but the number

of times I am right, outnumbers them!

( Also, when I am wrong, I get to find out..

in public! ;)

> Image url =

> jar:http://www.theWebServer.com/file/path/myApplicatio

> n.jar!/resources/images/logo.png

> Manifest url =

> jar:file:/C:/Program%20Files/Java/jre1.6.0/lib/javaws.

> jar!/META-INF/MANIFEST.MF

>

> Is not the same! :-))

>

> It is true: The first time when I want to read the

> manifest file. And I never imagene before: I read my

> application image, and I cant read the same manifest

> :-))

Good. It is not good that they are 'not the same',

but that you are beginning to understand some

of the traps and pitfalls, and ways to find out what

is going wrong. That is progress.

> But if in my main static method if I call:

> Thread.currentThread().getContextClassLoader().getReso

> urce("/resources/images/logo.png")

> this URL is null !!

> Why?

>

> I know I should learn something about classloaders,

> but when is changed the jnlp loader to a "normal"

> classloader. when I launch only the .jar file I have

> no problems, but I need webstart! :-)

I am surprised it worked from within main(),

in a jar file - it usually would not work for loose

classes off the local file system (but that is a

whole other story, to do with classloaders).

In any case, I think Caffeine0001 recently posted

some source that should help out, here. Check out

the source example he(/she) posted in this thread..

http://forum.java.sun.com/thread.jspa?messageID=4510193

It shows a way to find the actual file-system location

of a resource (your image, in this case), from which we

might construct an URL directly to the MANIFEST.MF

that you actually need.

Have a look/play with that source, and see if you

can include it into your code, so that we can see

where the image is being cached to.

AndrewThompson64a at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...
# 6

> > You have right!

>

> ..I am regularly wrong, ...

And here is a classic example..

> In any case, I think Caffeine0001 recently posted

> some source that should help out, here. Check out

> the source example he(/she) posted in this thread..

> ttp://forum.java.sun.com/thread.jspa?messageID=4510193

>

>

> It shows a way to find the actual file-system

> location

> of a resource ...

No it does not! I thought it did, but should

have checked more closely. It simply used

getResourceAsStream() to get the required

resource and never worried about the location

it was coming from..

AndrewThompson64a at 2007-7-7 17:06:03 > top of Java-index,Desktop,Deploying...