Run .jar as .exe


เรียกใช้งานไฟล์ .jar ของจาวา เหมือนเรียกใช้ไฟล์ .exe .com .bat ทั่ว ๆ ไปของวินโดวส์

Run Java jar file from Windows 2000/XP command-line like a native executable. A technique from James Clark (I got it from XML Hacks book).

At a command-line, type these two commands:

assoc .jar=jarfile

ftype jarfile=(JAVA_HOME)\bin\java -jar %1 %*

Then, change PATHEXT and PATH environment variables.
Right-clicking on My Computer, select Properties. Select Advanced tab, then Environment Variables.

Looking for PATHEXT variable, append “.jar” to its value.

Looking for PATH variable, insert “.” (dot, which means current directory) at the beginning of its value.

You got it!

Now try it. Say, if you have a file notepad.jar. To run it, instead of typing:

java -jar notepad.jar

you can just type:

notepad

Better? 😉


2 responses to “Run .jar as .exe”

  1. แบบนี้ทำทีเดียวไงแล้วจะ jar ไหน ไดเรกทอรีไหน ก็ใช้ได้หมดเลย

Leave a Reply to fat dog fatherCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.