Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
student:java:jar [2023/09/04 14:51] bernstdhstudent:java:jar [2024/01/28 14:59] (current) bernstdh
Line 1: Line 1:
- 
 ===== The Java Archive Tool (jar) ===== ===== The Java Archive Tool (jar) =====
  
Line 43: Line 42:
 You can create an executable JAR file by including  a manifest that includes a ''%%Main-Class:%%'' directive.  For more information, see the  [[ http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html | tutorial ]]. You can create an executable JAR file by including  a manifest that includes a ''%%Main-Class:%%'' directive.  For more information, see the  [[ http://java.sun.com/docs/books/tutorial/deployment/jar/appman.html | tutorial ]].
  
 +==== Running an Executable .jar File ====
 +
 +You can run an executable .jar file from a command shell/terminal window as follows:
  
-==== Permissions and Executable .jar Files ====+  - Open a command shell/terminal window. 
 +  - Change the working  directory to the directory that contains the ''%%.jar%%'' file (using the  [[https://ss64.com/|cd command]]) 
 +  - Execute the application as follows: ''%% java -jar //filename//.jar %%''
  
 +You can also run an executable .jar file from a file explorer/finder by double-clicking on it. However, your associations and permissions must first be setup.
  
-Depending on your operating system, you may need to change the  permissions of the executable ''%%.jar%%'' file (i.e.,  provide permission to execute). In most OSs this can be done from  the command line (using ''%%chmod%%'') or from the GUI  (in a variety of different ways).+===== Permissions and Executable .jar Files =====
  
 +Depending on your operating system, you may need to change the  permissions of the executable ''%%.jar%%'' file (i.e.,  provide permission to execute). In most OSs this can be done from  the command line (using the  [[https://ss64.com/|chmod command]]) or from the GUI  (in a variety of different ways).
  
-You may also need to set the default manner in which it is  "opened" (i.e., instruct the OS to used the Java runtime). This is  sometimes also called the files "association" or "default  program". From the command line: in MS Windows you can  use ''%%assoc%%'', in OS X you can edit  ''%%~/Library/Preferences/com.apple.LaunchServices.plist%%'',  and in Linux you can edit  ''%%/usr/share/applications/defaults.list%%'' From the GUI:  in MS Windows you can click on <key>Start</key>+<key>Default  Programs</key>, in OS X you can right-click on the file and  use <key>File</key>+<key>Get Info</key>, and in Linux you  can right-click and select <key>Properties</key>+===== Associations and Executable .jar Files =====
  
-==== Testing an Executable .jar File ====+You may also need to set the default manner in which it is  "opened" (i.e., instruct the OS to used the Java runtime). This is  sometimes also called the files "association" or "default  program". From the command line: in MS Windows you can  use ''%%assoc%%'', in OS X you can edit  ''%%~/Library/Preferences/com.apple.LaunchServices.plist%%'',  and in Linux you can edit  ''%%/usr/share/applications/defaults.list%%'' From the GUI:  in MS Windows you can click on <key>Start</key>+<key>Default  Programs</key>, in OS X you can right-click on the file and  use <key>File</key>+<key>Get Info</key>, and in Linux you  can right-click and select <key>Properties</key>.
  
-If you just click/double-click on an executable ''%%.jar%%''  file and the code throws an exception you (typically) won't see  it. Hence, when testing it is often useful to run the application  from the command line. To do so, open a command shell (sometimes also called a terminal), change the working  directory to the directory that contains the ''%%.jar%%'' file (using the ''%%cd%%'' command),  and then execute the application as follows:+==== Testing an Executable .jar File that You Created====
  
-|   java -jar //filename//.jar   |+If you just click/double-click on an executable ''%%.jar%%''  file and the code throws an exception you (typically) won't see  it. Hence, when testing it is often useful to run the application  from the command line. To do so, see the relevant instructions above.
  
 If you get a message like the following: If you get a message like the following: