I made a chess game with a gui, using images for the pieces. It works perfectly when run in eclipse. However, I tried exporting the jar (from eclipse) and running it in cmd but none of the images appear (the game itself however works perfectly, i just have to guess where the pieces are).
I'm going to assume that there is an issue with the addresses of the images...
The problem is, I can't even seem to be able to open any of the files within the jar file to see what, if anything is going on.
In eclipse, all the images were in a package within the scr folder, and they are definitely within the jar.
Any advice?
If you want to load images within your jar file you will need to use the
Class.getResource(String) method.
For detailed instructions see the How to Use Icons section in the Java Tutorial.
Related
I made a version of an 2D game by using an applet, java awt and some little java swing. I made a start-class containing a main method in order to export it as a runnable jar file.
The exporting works fine, without any problems.
But when its done and i try to double click the runnable jar file, nothing happens.
When I test it using the run button in eclipse everything works fine...
In the first moment I thought that my start-class may be the issue, but that's not the case. I tested it on an other applet, and there the runnable jar file using the same start-class works fine.
Now my question is: What could be the issue that prevents my runnable jar file from doing stuff when I double click it?
I found the mistake.
I've imported all the pictures i used in this game by using ImageIO.
I typed the names of the Images without a capital letter at the beginning, whilst the pictures in the folder actually had a capital letter.
Java eclipse did not care about it and it worked when i tried it out, but when i tried to open it with the command line, it didnt work aswell as it didnt work with a normal doubleclick.
i hope this helps others who got the same issue ^^
try right clicking on the file, select 'open with', 'Choose default program' and then select java Java(TM) Platform SE binary. If you don't see that option you should search for the javaw.exe in your java installation folder and select it. Also you should check Use the selected program to open this kind of file
As the title says, my jar file don't executes when i double click on it.
Before I updated the JRE and exported the runnable jar file it worked perfectly fine.
But after the update when i extracted the same project not a single line of code runs.
I have tried the existing answers here with no luck so i decided to ask my own question. My project is a game with pictures, music and textfiles and yes they have the same paths from the working jar.
Regards
Edit:
So i moved my project to a new computer with JDK 1.8.0.77 and extracted a runnable jar file but without any difference. However on this computer I can extract another project containing pictures etc and it's working perfectly fine.
The problem might be in my code then but the error must be early because no display comes up and the process doesn't show under processes. How can i debug jar files?
So the problem was my code all along, one of my 100 classes was creating a textfile and it seems like the jar file crashes when it did.
Sorry for taking up your time but I appreciates your answers. Now I have better understandings using JRE/JDK and jar files.
Thanks
I have a java application. And It loads images from a directory
"C:\\Users\\elliotbewey\\Desktop\\IMGS\\BOB.png"
And it loads fine the image displays. Now If I was to compile it into a runnable jar and send it to my friend. it would not work. What would I need to do get a installer? And get system information? Help!
//note I do understand that its going to my friends computer so \\users\\elliotbewey would not work because its his computer thats what I need help with
You need to package your images inside your jar, then reference them as resources. Doing a google search for "java package images inside jar as resource" will give you a ton of results and tutorials.
This approach will work from an IDE on your computer or from a packaged jar on your friend's computer. Using an installer is definitely overkill for this goal.
Locate your images inside jar file (for example res/image.png).
Then simply call this to get BufferedImage:
BufferedImage image = ImageIO.read(YourClassName.getClass().getResourceAsStream("/res/image.png"));
(4/15/2014 Still no working answer to the question)
I used gdx-setup-ui.jar to create my Android/Desktop/HTML5 program which I imported into Eclipse.
myprogram
myprogram-android
myprogram-desktop
myprogram-html
My program runs fine on desktop and android, but when I run it as html I get an error if all of my classes are not in the same myprogram>src folder, if I put it in a sub folder in src then the html5 does not seem to access the class. If I take my classes out of the folder and put them in the root of myprogram>src they work. How can I fix this?
I also notice that when I do a symbolic link to the asset folder manually(without gdx-setup-ui.jar) my Java application will not find the pictures etc unless I physically copy the asset folder twice. I made sure the folder path was exactly the same and it still wouldn't detect it unless I made a second copy of the pictures. Strangely the gdx-setup-ui.jar does this symbolic copy and yet it works for some reason.
This tutorial explains how to do it in Eclipse. And for completeness sake, here is how to do it using ant and IntelliJ. I hope this was useful. I will try the Eclipse one now...
I am working on Java project (A terraria like sandbox game) and I have come across something that I just don't understand. I have been exporting the project as .jar's as I go along to upload and share with my friends, but the last time I did this, the .jar won't run, but when I run it in eclipse, it runs fine. When I try to run the jar all it does is lose focus on the explorer window for a split second, then goes back. I have tried many things, like changing the main class, changing the META, and moving the files to specific packages, but nothing is working.
The project is 9 classes, so I won't paste all the code for it here, but the latest, non-working source code can be found here (http://www.mediafire.com/?fiw6wq73j7cff4t), the non-working jar here (http://www.mediafire.com/?bhjo162oh3hi2j9), and the working jar here (http://www.mediafire.com/?h918s8xpyxw4psr). If someone with more experience in java could please take a look at this it would be much appreciated.
One of the things I tried was not adding the JPanel (the game), and just leaving the splash screen, and the jar worked. This shows that it must be a problem in the coding somewhere.
Thanks for the time,
I.D.
Couldn't find message comes from your ReadMap class. So check which circumstance leads to this error. Most likely you did not add all classes or other files to your JAR, so file is not found. Check that all needed files are added to exported JAR in Eclipse export dialog. It's also a good idea to provide more debugging info (stacktrace is ok), especially when you are studying. BTW, cool game :)