Posts

Creating an Executable Jar File

In Java, it is common to combine several classes in one .jar ("java archive") file.  Library classes are stored that way.  Larger projects use jar files.  You can create your own jar file combining several classes, too.  jar files are created using the jar.exe utility program from the JDK.  You can make your jar file runnable by telling jar.exe which class has main .  To do that, you need to create a manifest file.  A manifest is a one-line text file with a "Main-Class" directive.   For example: Main-Class: Craps This line must end with a newline.  A jar file created with a main class manifest can be used both as a library and a runnable jar.  If you use it as a library, you can edit and compile any of the classes included in the jar, and add it to your project.  Then it will override the one in the jar file. You can create a manifest file in any text editor, or even by using the MS-DOS echo command.  You can give your manifest file any name,