#### Archived

This topic is now archived and is closed to further replies.

# [java] Jar Files

This topic is 5422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

My program(Level editor) works fine when I run it like this
java ELE
but when I got to jar it, it goes Failed to load Main-Class attribute from ELE.jar.. Here's what I'm doing.. The jar commands:
   jar cvmf add.txt ELE.jar ELE.class ELE*.class default
   Main-Class: ELE
trying to run it:
   java -jar ELE
Why won't it load? Oh and if this'll help the other files are ELE1.class ELE2.class..ELE10.class sorry for lack of originality of naming my stuff.. And I checked the jar file and all the files are there.. [edited by - eedok on October 7, 2003 5:25:20 PM]

##### Share on other sites
Make sure you have a newline after all the lines in the manifest file you''re giving it... Jar (the program) is a little stupid if you don''t, and will give you exactly the symptoms you''re describing.

##### Share on other sites
thx whoever you are, but now I''m getting null pointer exceptions when I go to load images.. This is starting to get annoying..

##### Share on other sites
Post some code outlining the problem, that way you can really get some help on it. The remainder of this post is a complete shot in the dark...

the classpath and all things associated with it (like manifests) are a ripe pain at first, but once you get them, they're cake.

your null pointers are possibly because the image's path is not in the classpath, that is if you're loading from the classpath (which is the easiest way to do it). Something like...

InputStream is =   getClass().getClassLoader()     .getResourceAsStream("bbb/to/image/in/classpath/image.png");// if (is == null) then classpath doesn't have bbb/.. in itBufferedImage myImage = ImageIO.load(is);

In that case, the folder (or jar, which is a bit more complex) that contains bbb/ needs to be in your classpath. If bbb/ is in the folder myProject/, then your classpath needs to be some equivalent of

someJar.jar:anotherJar.jar:/some/lib/dir:myProject

It all becomes second nature after a while, once you see how the JVM's using and interpreting the classpath.

[edited by - tortoise on October 8, 2003 2:11:25 AM]

##### Share on other sites
The error:
java.lang.NullPointerException        at javax.swing.ImageIcon.<init>(ImageIcon.java:138)

The line of code which the error appears at..
  ImageIcon Tilez=new ImageIcon(getClass().getResource("/default/1.gif"));

##### Share on other sites
That immediate slash is probably causing issues, I doubt that path should be absolute. Always use relative paths within classpath references, and their ''roots'' can be any entry in the classpath.

If that doesn''t help post how you are launching the program, your classpath, where you''re launching it from, etc.

Also, just a little note, you should almost always use getClassLoader(), as in

there are situations when the class loader can get the resource, but the class can not. This primarily is an issue when custom class loaders come into play, but with older JVM''s, or unusual ones (I know the JVM on the Sharp Zaurus is one), the getClass().getResource() may return null but getClass().getClassLoader().getResource() would not. It''s just safer (I''ve been bitten by this at unexpected times).

##### Share on other sites
Umm... maybe this is a noob question, but shouldn''t the backslashes be doubled? like:

ImageIcon Tilez=new ImageIcon(getClass().getResource("//default//1.gif"));

instead of what you have? It may be irrelevent and immaterial... but it still bugs me

##### Share on other sites
quote:
Original post by TreizeSG
Umm... maybe this is a noob question, but shouldn''t the backslashes be doubled? like:

ImageIcon Tilez=new ImageIcon(getClass().getResource("//default//1.gif"));

instead of what you have? It may be irrelevent and immaterial... but it still bugs me

What you are using is a forward slash. Forward slashes do not have to be doubled. If you were using a backslash(\), then yes it would have to be doubled.

You may also want to drop the initial ''/'' from the path, like this:

First make it work,
then make it fast.

--Brian Kernighan

The problems of this world cannot possibly be solved by skeptics or cynics whose horizons are limited by the obvious realities. We need men and women who can dream of things that never were. - John Fitzgerald Kennedy(35th US President)

Do not interrupt your enemy when he is making a mistake. - Napolean Bonaparte

##### Share on other sites
check this out...
To jar or not to jar

Glass_Knife
I think, therfore I am.
I think?

##### Share on other sites
that article doesn''t help at all..
getClassLoader() and relative paths don''t work either..

1. 1
2. 2
JoeJ
20
3. 3
frob
17
4. 4
5. 5

• 10
• 10
• 11
• 13
• 9
• ### Forum Statistics

• Total Topics
632197
• Total Posts
3004728

×