2

My program is a small command line based game. If I export it as a runnable .jar, everything works great, but starting the application is inconvenient. When you just click on the .jar, nothing happens. You have to open in via the console with "java -jar XXX.jar"-command.

Is there any solution that the user only has to click the .jar, and then a console pops up and the program starts?

I thought about wrapping the .jar into an .exe, but I have no experience with this, and do not know how it's done or which program to use for this.

Thanks in advance!

Philipp

atk
  • 9,244
  • 3
  • 32
  • 32
PKlumpp
  • 4,913
  • 8
  • 36
  • 64
  • 2
    Create a `.bat` file and put `java -jar XXX.jar` in that file. – 4J41 Dec 22 '13 at 14:36
  • No need for a bat file. Just change your OS settings to call java -jar when jar files are double clicked. this is not a Java question but basic OS set up question. – Hovercraft Full Of Eels Dec 22 '13 at 14:41
  • yeah, but this will only work for my system. if i send the game to a friend, he has to do the same, and so on. – PKlumpp Dec 22 '13 at 14:42
  • This looks like a rehash of another question. http://stackoverflow.com/questions/4330936/how-can-i-convert-a-jar-to-an-exe – VictorCreator Dec 22 '13 at 14:46

2 Answers2

1

There is a handy utility called Launch4J that will wrap your Java program into an exe.

http://launch4j.sourceforge.net/

Alternatively you could provide a .bat file or shortcut that calls java -jar app.jar

Frederic Close
  • 9,389
  • 6
  • 56
  • 67
Tim B
  • 40,716
  • 16
  • 83
  • 128
1

This is really simple ;)

  1. In Eclipse rightclick your project and select export.
  2. Select Java -> JAR File as the type
  3. On the next window, uncheck everything, except for generated class files and resources and the project at the top. Make sure to set the export destination.
  4. The next screen is usually fine.
  5. At the bottom of the last screen you have to select the main class, the class were your application should start.
  6. Click finish, and have fun ;)

If this was too confusing, i can add screenshots.

Lars
  • 500
  • 1
  • 7
  • 22
  • ok this works for me, but still when i click the .jar, nothing happens. maybe i am doing something wrong? java -jar XXX.jar is working :D – PKlumpp Dec 22 '13 at 15:04
  • Oh, i just read your question again and you say that your game is command line based. :/ Sadly jar files don't seem to handle command lines too well on double click. Have you considered writing your own window with just a textarea inside? This would give you more control over the output too. – Lars Dec 22 '13 at 15:09
  • you are right. this might come in handy in further development stages. i think i will use a .bat file as a work-around for now, which I just tried and it works fine. for future versions of my game, designing a custom little console could be very nice. THX! – PKlumpp Dec 22 '13 at 15:29