Runnable jar file generated with java eclipse wont run when double clicked - java

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

Related

Trouble executing a jar file

I am trying to run a executable jar file I made in Intellij on JDK 11.0.2 that contains a GUI system. I have java 8 and Java SDK 11.0.2 installed. Whenever I double click the jar file I expect the main gui login screen to come up, but nothing happens. I have tried other options such as trying to run it through cmd (it gave me an access error) and the HKEY_CLASSES_ROOT\jarfile has the command: "C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe" -jar "%1" %* already.
Cant comment quite yet on other peoples posts so ill just submit an answer, tho its gonna be more of a swing and miss probably.
Id recommend opening that jar file with a java decompiler (The one i had in mind is jd-gui) and checking the integrity of the code, file system, and, in general, just check arround for common errors when packaging, maybe you included something you shouldnt in the class and hence why the problem, or its crashing on load cause of a missing reference you had linked to with a relative path which got broken upon moving the file, those are the two big ones that come to mind that you should check first upon opening the file, other than that, i cant provide much more insight, godspeed to you!

Java opening files - works from Eclipse, doesn't work in runnable JAR/exe

I have some java code that I'm using to open a file:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + output.getAbsolutePath());
It works just fine when I execute it from Eclipse, however, when I export the project to a runnable JAR, the functionality stops working. I've tried various different options to open the file (Desktop.open, ProcessBuilder etc.) all with the same results (Eclipse OK, runnable JAR not).
This exact code previously worked when I exported it in the past (1.5 years ago). I believe that was with Java 1.6 and now we're on Java 1.7. Not sure if that's the reason though and I don't have the option to compile using previous versions of Java. Any ideas?
thanks for attempting to help. I figured out the answer which is quite simply that I'm an idiot :) Opening the file wasn't the problem, the file wasn't being written in the first place, and the reason it wasn't being written was quite simply because the code was set to write it into a nested folder structure which had not yet been created. I didn't even think of this because I assumed that any necessary folders specified in the output string would be created automatically. Doh!

Double clicking jar file wont execute after update JRE

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

Executable jar file won't run after doing some updates

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 :)

Executing .jar files with a double click

I've been using Eclipse as my Java IDE and today I ran into an interesting problem. I used the built in file>export>runnable jar file to create a jar file for one of my programs. It runs perfectly if I start it from the command line/with a batch file, but doesn't run from a double click. I made absolutely certain that .jar files are associated with javaw and it still didn't work. It isn't a huge problem I absolutely NEED fixed, but if anyone has any ideas I'd love to hear them.
Update: I tried using Aram Kocharyan's solution (see answer below). No luck. It seems to be just this one .jar file too. All other jars launch with a double click. Rebuilding the jar doesn't help. :P
I wrote a short guide on this a while back you might find helpful:
http://ak.net84.net/projects/how-to-make-a-multi-platform-executable-java-jar-file/
This will work on double click in windows without setting any additional settings, and I've tested it with the Jar Launcher on Mac and it doesn't complain.
open your jar with..javaw
which is in bin folder of jre... in my computer it is #
C:\Program Files\Java\jre\bin\javaw.exe
Put this inside a .bat:
start javaw -classpath "%~dp0YOU-JAR-NAME.jar" -Djava.library.path="native" foo.package.bar.YourClassWithMainMethod
the option -Djava.library.path="native" its not required for run, i include this because one reason for using a .bat instead do a double click on a .jar is to use JVM-parameters, in my case i need this parameter for my project run.
the %~dp0 part get current directory

Categories