Creating a JAR file

I’m no Java programmer, but we used Magnolia CMS, a Java-based content management system, for creating interactive online learning materials, so have to mess about in the world of Java from time to time. In order to make modifications to the modules that we use for Magnolia (generally minor bug fixes or alterations to make them better suited to our needs), we have to unpack, edit and then repack .jar (Java ARchive) files. I always forget how to repack the jar files, and have recently had to set up a new PC to do it, so here’s the process I used, in case it is useful to anyone (especially the future me):

  • Get and install the latest Java Development Kit: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
  • Add the location of the JDK bin (where jar.exe lives) to the Windows Path environment variable (Windows 8, but similar for other Windows versions):
    • Go to Control Panel > System > Advanced system settings > Environment Variables…
    • Under System variables, find the Path variable, select it and click Edit
    • Add “;C:\Program Files\Java\jdk1.7.0_21\bin” (or whatever the path to you JDK bin directory is – it will be something like this if you install with the default location settings) at the end of the Path variable
    • This will enable you to run jar.exe by just typing “jar …” in the command line
  • Open a command prompt and navigate to the directory containing the class files etc that you want to “jar”
  • Use this command to create the jar: “jar cf jar_name.jar *”
    • c = create new archive
    • f = specify file name
    • * = add all of the files in the directory to the jar
  • That’s it, you should now have a new jar file called “jar_name.jar”

 

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.