JAR FILES

A jar file allows you to bundle a group of java classes (e.g., a project in BlueJ or JCreator, for example) into a single archive. In most operating systems, java program execution simply involves double-clicking the jar file. Here are the steps needed to build a jar file (try it on one of our JFrame examples):
  1. Make sure all java programs required for execution of the project are compiled in one folder.
  2. In that same folder, create a text file (e.g., main.txt), containing a single line:
    Main-class: MainProgram
    
    where MainProgram is the java class that contains the main method. (Important: there should be exactly one space after the colon.)
  3. Execute a command prompt, cd to the folder containing the .class files and main.txt, and type:
     jar cmvf main.txt PROG.jar *.class 
  4. A PROG.jar file will be created. Move that file anywhere in your system, double-click, and watch your program execute.