Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jar file error

 
Iantra Solari
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everyone, i'm quite new at java and i remember making a jar file a while ago, and it took me some time to make it work correctly.
Now, i made a simple game file but i can't seem to remember how to make the .jar file work. I have all the classes and the manifest file, and they run perfectly on eclipse, but when i make the .jar i get the "main class not found" error.
I cant attach all the files, so i uploaded the .java files, the .class files, the manifest and the jar files here, i hope someone can help me...


Oh, and here's the other .jar file which i got working
 
Rob Spoor
Sheriff
Pie
Posts: 20510
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you double click a JAR file it's executed using javaw.exe. That one has terrible error handling; any exception or error thrown from the main method is displayed as that stupid message you mentioned.

Try executing the JAR file using java.exe: java -jar Game.jar. You will then see the actual error. In this case the problem is packaging; your class is in package test, so the full class name is test.Game. That must be the name of the Main-Class in the manifest, but it also means that inside the JAR file there must be a folder called test in which the Game.class file is located.

Also, resources use / as separator, not \ (which is escaped to \\).
 
Iantra Solari
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, now the file opens but i just get a black screen for a couple of seconds and then it closes. What could be the problem? it works perfectly on eclipse.

Edit: whoops, i forgot about the cmd error:



Edit2: I looked around my java file a bit and all the errors seem to be based in this line:

I checked for background.jpg in the .jar file and it's there, and i don't see anything wrong/different from the character codes except for the .jpg extension, but it works in eclipse.

Edit3: Finally, i got it to work by deleting all package thingies and putting everything in the same folder, thanks for the help ^^

So... the code will work if i put the .pngs and the .classes in the same folder, but it won't work if i put the .pngs in Images\... any idea why this happens? (I do realize i have to change the java path to Images\background.png instead of background.png)
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You seem to be under the impression that the getResource method expects a file name. It doesn't. It expects a URL. (Check the documentation and you'll see that for yourself.) So provide a valid URL:



And if that doesn't work, decipher the obscure description of the getResource() method which says that a relative URL is relative to the class which is calling it. So if your class name is test.Game, the absolute URL for that example would be /test/Images/background.jpg. If that wasn't where you put the image, then chances are you needed an absolute URL:

bg
 
Iantra Solari
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
umm... sorry if i'm kinda dumb but im VERY new at java, so i tried the urls like you said but they aren't working(the Game isn't in the test package anymore so i didn't try the /test/Images) it keeps telling me there's an error with that line. If it's too hard to tech me or i'm too dumb to notice the error im having then don't worry, i can live with having the images in the same file as the classes.
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iantra Solari wrote:it keeps telling me there's an error with that line.


"It"?

"An error"?

We may all be incredible geniuses here, but we aren't mind-readers. Please spend a few seconds to describe the problem. What tells you there's an error? And precisely what does it tell you?
 
Iantra Solari
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It = The program;



that WAS the error. However, i found a solution by changing the image code, thanks for the help everyone.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic