1

This is more curiosity than a problem:

I was recently wondering if there was a way to run compiled Java applications without using the cmd or an IDE such as Eclipse. I use Eclipse, but it isn't very useful if you want to run the program independently. Can you save Java files in Windows Explorer so you can create a shortcut for them? If so, how? Is there some sort of special extension to the file? I've heard of .JAR files, but I'm not sure what they are. Can anyone tell me how to do it?

imulsion
  • 8,820
  • 20
  • 54
  • 84
  • Here's a good overview of [JAR files](http://docs.oracle.com/javase/tutorial/deployment/jar/). – maerics Jul 19 '12 at 16:42
  • [This answer](http://stackoverflow.com/a/394628/95033) might help running a Java application in Windows. – Wolfram Jul 19 '12 at 16:42
  • in windows even if you dont type a command into cmd, clicking a shortcut still executes the command.. double click a compiled a java file ( with the main class) and choose java.exe to run it. It should theoretically work. dont have any java files on me atm to test it.. jar files are generally how you put the entire java program together. it is pretty much a zip file with a proper structure and instructions about launching the java program). So generally if you want to give some one else your java program to run, generally we give them a jar since they dont need to know which file has main. – Osama Javed Jul 19 '12 at 16:45
  • I seem to recall Eclipse has some kind of 'export to jar' functionality. Once I had the jar, on Windows, I was able to just double click the jar, as .jar files had been associated with java.exe (as Osama just pointed out). – Jason Dunkelberger Jul 19 '12 at 16:47
  • possible duplicate of [Running Jar file in Windows](http://stackoverflow.com/questions/394616/running-jar-file-in-windows) – ataylor Jul 19 '12 at 16:49
  • Right, made the JAR file with my program helloworld.class in it. Which program should I use to run the JAR? – imulsion Jul 19 '12 at 17:31

2 Answers2

1

.JAR files are archives containing - amongst other things - your compiled classes and a manifest file. You may set the main entry point of your application in that manifest. See Setting an Application's Entry Point.

Normally if you double click a jar file in windows it will be opened by javaw.exe -jar <yourFile.jar>. javaw.exe will lookup the manifest and try start the main class defined there.

Arne
  • 2,106
  • 12
  • 9
0

create the jar file for java application using following syntax jar -cvf .jar . then use javaw.exe -jar

SIVA
  • 11
  • 2
  • 6