Amno
Amno

Reputation: 1

the .jar file does not execute when I click on it

I know this question would sound very stupid, but this is my first java program after all. K, the question is, when type this: java -jar JavaApplicationTest.jar the program executes without problems, but when I go to the folder where the JavaApplicationTest.jar file is, and click on it, it does not execute. I thought that .jar files were like .exe file, are they? I mean, in the way that we click on them and the program runs; 'cos the java virtual machine is running in the back ground. Please, any help would be very much appreciated.

Upvotes: 0

Views: 107

Answers (3)

duffymo
duffymo

Reputation: 308813

No, they aren't exactly like .exe. Only .exe is an .exe.

When you execute a JAR file, it's the Java JVM that's running, not your JAR file. The JVM opens the JAR, loads the .class byte code, and executes the main class that you specified in the META-INF.

I'm guessing that your Windows operating system is doing something besides running the JVM when you double click. Try right clicking and seeing what options your Windows operating system presents to you. If one of them is to unzip the file, you'll have to add running the JVM as another choice.

Upvotes: 1

thinkinjava
thinkinjava

Reputation: 95

Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed.

Upvotes: 0

user4668606
user4668606

Reputation:

The jar-file runs. But there's a big difference between: java -jar someJar and someJar.jar/respectively double-clicking on the jar. The full command launches the jar in the same commandline, in which you have entered the command. Double-clicking on the jar creates a process aswell. But with a completely separate console-window that is hidden.

Upvotes: 0

Related Questions