Results 1 to 5 of 5

Thread: What is JAR file? Please explain

  1. #1
    Join Date
    Feb 2009
    Posts
    4

    What is JAR file? Please explain

    Hi,

    Can you please explain me what is JAR file? How to execute it?

  2. #2
    Join Date
    Feb 2009
    Posts
    8

    Re: What is JAR file? Please explain

    JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory. A JAR file can be created by the command-line jar tool, or by using the java.util.jar API in the Java platform. There is no restriction on the name of a JAR file, it can be any legal file name on a particular platform.

    In many cases, JAR files are not just simple archives of java classes files and/or resources. They are used as building blocks for applications and extensions. The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services.

  3. #3
    Join Date
    May 2008
    Posts
    115

    Re: What is JAR file? Please explain

    A JAR (Java ARchive) file is a file that contains the class, image, and sound files for a Java application or applet gathered into a single file and possibly compressed. When a programmer gets a Java program development kit, a small program or utility called "jar" is included. The jar utility lets the programmer create, list, or extract the individual files from a JAR file. In an enterprise, a Java application can be started with a set of JAR files for use during execution. An off-the-shelf open source package can be delivered as a JAR file and run with XML data.

    On the Web, a JAR file containing an applet may accompany a Web page. By putting the applet components in a single file and compressing that file, download time is saved. Ordinarily, a browser user will not need to "open" or view a JAR file directly. It is opened when the Web page is received and the applet is in some manner initiated.

    The JAR format is based on the popular zip file format and is somewhat comparable to the Unix tar file.

  4. #4
    Join Date
    May 2008
    Posts
    40

    Re: What is JAR file? Please explain

    Java Archive (JAR) files are compressed files into which you can store many files. If you place the many classes that your application, or applet need in a JAR file, you reduce the size of your distributabels.
    To create a JAR file, go to the directory where your files are located and type:


    jar -cf ajarfile.jar *.*

    and every file and directory in the current directory will be in a file called ajarfile.jar.
    If you like to see what the JAR tility adds to the jar file, type:


    jar -cvf ajarfile.jar *.*

    The "v" option sends the JAR utility to a verbose mode, printing out information about its activities.
    If you want to extract the content of an existing JAR file, type:


    jar -xf ajarfile.jar


    Again, if you like to see files (or directoies) that the JAR utility extracts from the JAR file, use the "v" option, as in:


    jar -xvf ajarfile.jar

    If you like see a table of content of a JAR file, type:


    jar -tf ajarfile.jar

    Again, you can use the "v" option to see some information about the files in the JAR file, as in:


    jar -tvf ajarfile.jar

    There are other options with the JAR utility, to see them just type:


    jar

    If you have a UNIX background, you might have realized the definite similariries beteen JAR options and the options of UNIX tar utility.

  5. #5
    Join Date
    May 2008
    Posts
    13

    Re: What is JAR file? Please explain

    Creating executable jar files

    A new and cool feature of Java2 is the ability to create executable jar files. A jar file is simply a file containing a collection of java files (typically, java .class files, but any other kind of file could be included as well). To make a jar file executable, you need to specify where the "main" Class is in the jar file, so the "java" command knows what main() method to invoke to get the software going.


    # First, make sure you have installed Java 1.2 or above. This facility is not available in previous versions of Java.

    # Next, create your working java system. In general, you will want to put it into a package. For this example, I created a trivial HelloWorld application that prints out "Hello World" plus the first command line argument, and placed it into the package "psae". Therefore, the HelloWorld files (HelloWorld.class, HelloWorld.java) were located in the directory psae. I tested the system to make sure it worked before going on to the next step.

    # In the directory in which the psae is located, created a file called "mainClass". This file contains a single line specifying where the main Class is to be found in the jar file. Note that I use the package specification. Here is the single line:

    Main-Class: psae.HelloWorld

    Note: make sure you type a carriage return after this line; some windows systems need it and will report a "Failed to load Main-Class manifest attribute" error.

    # Next, I create a jar file called psae.jar using the "jar" command in Java2. I use the "m" command line argument to specify the manifest file mainClass, which adds information to the jar file on where the main class will be found. Here is the jar command:

    bertha:~ > jar cmf mainClass psae.jar psae

    # Just for fun, and to check what's happened, I print the table of contents for the jar file I just created. Here's the command and its result:

    bertha:~ > jar tf psae.jar
    META-INF/
    META-INF/MANIFEST.MF
    psae/
    psae/HelloWorld.java
    psae/HelloWorld.class

    # Having successfully created the jar file, I can now invoke java2 on it with the command line argument:

    bertha:~ > java -jar psae.jar Bofinn

    Hello World Bofinn

Similar Threads

  1. Explain an MP3 Encoder
    By Juily in forum Windows Software
    Replies: 4
    Last Post: 09-09-2011, 07:59 PM
  2. Explain me about dbx in PHP!!
    By Steyn in forum Software Development
    Replies: 5
    Last Post: 07-03-2010, 04:50 AM
  3. Explain the Global.asa file and ASPError Object in ASP
    By Juan-Carlos in forum Software Development
    Replies: 5
    Last Post: 22-12-2009, 06:12 AM
  4. Explain Response file in C-Sharp
    By KAMANA in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 04:17 AM
  5. Explain STL
    By KAMAL60 in forum Software Development
    Replies: 3
    Last Post: 10-11-2009, 05:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,422,530.27882 seconds with 17 queries