The program I write in Eclipse runs on console purely. I hope to export it to a jar file then use launch4j make it an executable .exe file. The program should desirably be opened in cmd or terminal on Mac once clicked. But it seems I can't open it with cmd and unless I used swing or awt, nothing to show when I clicked either jar file or exe file. So what is the problem and how should I do to make it runnable on cmd! PS:I dont want to type any command line, just click the jar file or exe file and it started to run on cmd or terminal!
Asked
Active
Viewed 3,493 times
3 Answers
1
You would possibly try script files for this task:
windows: run.bat
java -jar your.jar
mac: run.sh
#!/bin/bash
java -jar your.jar
-
Thank you it works on Windows now. But what if I converted it to an exe file, how should I run? – Zoe Nov 12 '14 at 06:00
0
This Answer shows the use of Jar Bundler to convert jar to executable native Mac OS X .app executables
I think you can give it a try. Enjoy!
Edit
Jar2Exe seems promising to convert jar file to executable for Windows and Linux Platform.
You can try them and let me know too if that work for you.

Community
- 1
- 1

Shubhang Malviya
- 1,525
- 11
- 17
-
It works with jar file now, but not with exe file. I double clicked and there is nothing to show with exe – Zoe Nov 12 '14 at 06:33
-
@Zoe I have updated my answer , check if that works for you (if you're still looking for an answer ;)) – Shubhang Malviya Nov 21 '14 at 09:19
0
launch4j could work on windows/osx/linux, but I think you need a mac to build the executable file. And the jar file itself can be run when double-clicked, if you specify the Main Class in META-INF/MANIFEST.MF file, like this:
Main-Class: com.xxx.xxx.YourClass
After this, the jar file could be double-clicked to run.

sanigo
- 625
- 4
- 14
-
When you export jar file from Eclipse, you can specify the Main Class, so you need not edit the manifest file manually. – sanigo Nov 12 '14 at 06:15