• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Run Java program as standalone

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
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.)
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

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
javac <path>/TestExport.java
java <path>/TestExport
 
Jan Seer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to allow end users to run the program by double clicking then you may want to look into JNLP.

A simpler approach is to have a Windows batch or Unix/Linux shell script to call the java program.

About the error messages, if your app is GUI, then you may want to have a status bar or pop up (dialog) to show the errors.
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

More information and links on jar files is at https://coderanch.com/how-to/java/JarFiles
 
Jan Seer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
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:

 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jan Seer
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
Did you just should on me? You should read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic