1

I'm new to java and have recently created a stress testing application to test server configurations. Its very simple and all is done within cmd line. I used eclipse to create the jar file and that seems to have worked fine.

The problem that I am running into is making this executable. If I use java -jar in windows cmd line to execute the program, it runs fine. However, I need to be able to run it by "double clicking" the jar file(right now I click on it and nothing happens) or create a .exe which defeats the purpose of java, but this will only be used in windows.

When I click on the jar now nothing happens, but when using the java - jar in cmd it works. Not all of the computers have java in the cmd line, but have it installed. I'm not sure why a cmd window doesnt pop when clicking on the jar?

Again I'm new and any help is much appreciated!!

mve9302
  • 13
  • 1
  • 4

4 Answers4

2

Create a sortcut icon that will do java -jar yourFile.jar

Naftali
  • 144,921
  • 39
  • 244
  • 303
  • The problem with this is that not all computer here(just devs have java setup to run in cmd line). So it has to be something that doesn't require java cmds in cmd line – mve9302 Jun 27 '11 at 19:47
0

In windows, you can associate the jar file with the JRE jar runner. Take a look at this post, which explains your options pretty well.

Community
  • 1
  • 1
Ryan Gross
  • 6,423
  • 2
  • 32
  • 44
0

Make a bat file for Windows. You can do this by the following:

@echo off
java -jar YourJarName.jar

Save this in a text file with the .bat extension.

It should run the JAR once double clicked if the JAR file is in the same directory as the .bat file. Otherwise you will have to navigate to the JAR file relative to where the .bat file is located.

You said you didn't want an exe but not sure if this will be ok for you. It shouldn't be a problem for someone to click the .bat file first and will work in all cases under Windows.

Hope this helps.

adamjmarkham
  • 2,150
  • 2
  • 18
  • 26
  • The problem with this is that not all computer here(just devs have java setup to run in cmd line). So it has to be something that doesn't require java cmds in cmd line – mve9302 Jun 27 '11 at 19:48
  • I see the problem now. You probably want to go for the JRE jar runner in that case. – adamjmarkham Jun 27 '11 at 19:53
0

If you want to get really awesome with it and have it show up in your Task Manager with an app.exe naming and handle any startup options, you should read into JNI. JNI will allow you to wrap the starting and stopping of a Java app using a windows executable and it is actually very simple to implement.

If you want something as simple as a windows exe launcher, there are also tools out there such as Launch4j will create exe wrappers for you.

Josh
  • 2,955
  • 1
  • 19
  • 28