running a .jar file from the start=>run box in Windows 7
I've written some code and made a .jar file out of it, and I want to be able to run this code from the start=>run box in the Start menu. After a lot of trial and error, I made sure to construct my .jar file the right way, and I set the proper .jar file type association so that my computer recognizes to run the .jar file using java.exe.
Doing all this enabled me to run the .jar from the command window, typing "java -jar myJar.jar", but it won't run from the start=>run box (even when I add in the .jar's f开发者_开发知识库ilepath). What should I do? Also, I'm not sure if I could run a .jar from the run box that takes arguments - is it possible to do that?You'll need to tell Java which class to is the main class. If you intend to distribute the application you should probably make a Manifest file with a main-class attribute. See: http://download.oracle.com/javase/1.4.2/docs/guide/jar/jar.html#JAR%20Manifest
If you just want to get the damn thing running, this command should work...
java -jar myJar.jar MyClass
... analogous to how you'd normally write...
java MyClass
... at the command line.
BTW, it might be worth mentioning the javaw
command, which which works just like the java
but launches a graphical application without showing a command prompt, on Windows.
You should have a look at the links below:
http://download.oracle.com/javase/tutorial/deployment/jar/basicsindex.html
http://download.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
You probably did not add the the "Main-Class:..." in your manifest file.
http://download.oracle.com/javase/tutorial/deployment/jar/appman.html
You have to have a special entry in your MANIFEST.MF file inside your .jar that points to the entry point class in your .jar file to make it executable without specifying a class on the command line.
META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: [fully qualified path to the class with the main method]
精彩评论