I am quite new to Java and I am working on a personal project to learn the language. I use Eclipse (Kepler) as IDE.
Most things work well at the moment and I wanted to try to export my project so I can run it outside of Eclipse.
I used Eclipse's "Export" function to create a "runnable JAR". Here is my first question: Should I be able to run this file directly? Because when I double click it in the windows explorer, nothing happens.
I also tried to make an .exe out of that .jar by using "Launch4j". This worked without error messages, but the same as above: When I double click the .exe in the windows explorer, nothing happens.
At this stage, I thought I maybe made a programming error, so I created a test file which contains only the following code:
The result was the same as before: The .jar and the .exe are created without problems, but they simply do nothing...
Can anybody help me?
(Sorry if my English is not always the best, I am from Germany.)
When you create/export the JAR file, did you specify the "Main Class" in the manifest file? With a JAR file, you can execute it with "command" not double-clicking
java -jar MyFile.jar
Also if you did not make a JAR you should able to do the same by specifying the full path to the Main Class eg TestExport
K. Tsang CEng MBCS PMP PMI-ACP OCPJEA OCPJP
posted 6 years ago
Thank you, that helped me.
By using "java -jar MyFile.jar" in the command line, it is possible to run the test project as well as the real project, so my project seems to work like it should.
For the future, I want to give the program to some friends for alpha/beta testing and I would prefer to be able to start it the "usual" way for an end user, by double clicking it in the explorer. Is that also possible? The program has a basic GUI, but for error messages I currently use the usual System.err.println(), which requires the command line, right? In the final version, the command line should not be required anymore.
if you want to allow end users to run the program by double clicking then you may want to look into JNLP.
Well, if double clicking a jar file that runs fine via "java -jar MyFile.jar" does not run it, then anything more complicated like JNLP probably would not work either. That's just speculation, but apparently something went wrong during installing Java, because that generally registers jar files as double-clickable automatically. So I would advise to stay away from JNLP and .exe files for the moment. One thing to try would be to take the jar file to another computer and test its double-clickability there; maybe there's something wrong specifically about the Java installation on your machine.
I tried some additional things now: I brought the .jar to two different computers and I reinstalled the JRE on my laptop. The result is the same as before: I can start the program by using the command line but not by double clicking.
I also checked what the default program for opening a .jar is. I did a right click on the .jar, and choose "open with". The default (and the single available) program is "Java(TM) Platform SE binary", is this correct?
I also read this, but I did not find my problem. I also checked the manifest files. They seem to be correct, too.
Here is the manifest file of the test project:
posted 6 years ago
Try removing the "Class-Path:" attribute from the manifest.
The default (and the single available) program is "Java(TM) Platform SE binary", is this correct?
That sounds about right, but I don't have a Windows machine handy to verify it.
posted 6 years ago
Ulf Dittmer wrote:Try removing the "Class-Path:" attribute from the manifest.
I tried that now. Same result as always. "java -jar" works, double click not...
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?