JAR

From CS315

Jump to: navigation, search

What is a JAR?

Jar is wonderful! The invention of JAR has solved so many problems globally and domestically. Where would we be today without Jar? As enthusiastic as I appear, Jar is pretty useful when submitting many files. Keyword "Many"! The use of "Jar"ing is the necessity to provide someone with multiple files with just one file? How does this phenomenon work? Lets exam this.


How do we JAR?

There are many methods or mediums of Jarring:
   eclipse, http://www.eclipse.org/downloads/
   Command Prompt: MSDOS, In your computer, provided that you have JDK (J2SE Development Kit) & Windows OS 


Lets get started the HARD WAY!:

Prerequisites:

(1.) JDK installed: [1]

(2.) Files you want to archive

Steps:

(1.) Start/Run/

(2.) Type in this exactly as you see in quotes: "CMD" (Command Prompt-MSDOS)

(3.) Type in after "C:/Documents and Settings\" the location of the jar file

      - "C:\Program Files\Java\jdk1.5.0_14\bin\jar.exe" 
      - So far you should have: as is:
  C:\Documents and Settings\Whatever>"C:\Program Files\Java\jdk1.5.0_14\bin\jar.exe"

(4.) Now after all of the above...hit space and enter : cf which is a command to "create file"

      - Now you should have:
  C:\Documents and Settings\Whatever>"C:\Program Files\Java\jdk1.5.0_14\bin\jar.exe" cf

(5.) Now add the files you want to archive with a space in between them like so:

      C:\Documents and Settings\Whatever>"C:\Program Files\Java\jdk1.5.0_14\bin\jar.exe" cf hello.txt hello.java hello.cpp whatever.hot

(6.) After you have entered the contents you wanted to archive you need to name the file appropriate and push enter afterwards to indicate that you are done archiving and it should export to the location you had intially in command prompt:

    - example:
     C:\Documents and Settings\Whatever>"C:\Program Files\Java\jdk1.5.0_14\bin\jar.exe" cf hello.txt hello.java hello.cpp whatever.hot FILENAME.jar

(7.) There are many ways you can optimize this process, however for the simplistic sack this the most robust and long way to do it.

     - For ways to optimize this process you can go to:
     - [2]

Conclusion: The reason I went through this laborious method is to show you how we use to do it compared to what you can do now via some software that is installed with your IDE.


The EASY WAY:

Please make sure you have at least Eclipse installed on your computer with the JDK Kit as shown above.

eclipse, http://www.eclipse.org/downloads/

Eclipse is an IDE where you can compile and run programs that are java related. With this IDE you have special commands that will let you archive files that you are editing in your IDE.

Steps:

(1.) Assuming you have already compiled and run files and you have the files in your perspective.

(2.) File/Export

(3.) A box will come up asking you what files to archive and how you will like to archive.

(4.) Make sure you have assigned no class files to export and only source/java files to export.

(5.) You can simply check while files you want to archive and you are good to go ...

(6.) It will even let you name and choose where you want to the file to export to.


The SUPER EASY Way

Prerequisites:

(1): Have Linux (or another Unix-like OS, Mac OS X will do) installed.

(2): Have a version of the Java SDK installed.

(2.1): If you don't have Java installed: open up Terminal (or Konsole for KHippies) and type

sudo apt-get install sun-java6-jdk

Note: If you're not using a Debian based distribution, use whatever package manager your distribution has.


Operation:

(1): Open up Terminal.

(2): Type:

jar -cf filename.jar files you want to jar



Written by John Loyola

Personal tools