+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Creating an Executable Jar File

  1. #1
    TALucas's Avatar
    TALucas is offline Learning Programmer
    Join Date
    Dec 2008
    Location
    Illinois
    Posts
    92
    Rep Power
    12

    Creating an Executable Jar File

    This is my first attempt at a tutorial here at CC, so if it's out of place, or I'm out of place, just let me know...

    A Java Archive file (Jar) is a compressed file based on the ZIP format. Jar files can contain many files and folders, but most often hold Java .class files. This format helps keep all the files in one place, and reduce the overall size of a project. Another very useful function of Jar files is that some of them can be executed. The purpose of this tutorial is to explain how to create an executable Jar file.

    First I’ll make the assumption that you have downloaded and installed the Java SE Development Kit (JDK), and have also set up the PATH and CLASSPATH environment variables. If you can run and compile .java programs from the command line, then you’re set to go.

    First thing you need is a Java source file. A simple program that just gets and sends data to the command prompt will work as long as you run it from the command-line, but you will not be able to see any output if you just double click on the Jar file. So, in this tutorial I will use an example that creates a window using JFrame.

    Step 1. Create a folder called test and put your Java source file in it. For my example I’ve created a simple clock application that just counts the number of days since something has happened…the number of days since you’ve quit a bad habit, the number of days your website has been up, for me it’s the number of days since I joined Code Call…13 days at the writing of this tutorial.



    You can use the Clock.java example if you like or substitute one of your own. Go ahead and compile the source. You should now have a test folder that contains the source file, and two class files.



    Step 2. Create a manifest file…I’ll call mine Clock.MF. A manifest is basically a file that contains information about the files packaged inside the Jar file. You can create yours using a text editor, just give it a .MF extension. Here’s what needs to go in this manifest file:

    Code:
    Manifest-Version: 1.0
    Main-Class: Clock
    Created-By: 1.2 (Sun Microsystems Inc.)
    The first line tells us that this file conforms to 1.0 of the manifest specification. The second line tells which class inside the Jar file contains the “main” function. And the last line defines the version and the vendor of the java implementation on top of which this manifest file is generated.

    Step 3. Create the Jar file using the jar command. In the example below (jar) is the name of the executable you call to create the Jar file. The jar command has a number of options…I used four of them (c –create the jar file, v –generates verbose output to the screen during file creation, f –specifies the file to be created, and m –indicates the manifest file to be used) After the options parameter comes the name of the jar file to be created (clock.jar), followed by the name of the manifest file to use (Clock.MF). The (*) wild card indicates to include all files in that directory. If you wanted you could use *.class to only include class files. Here's the command:

    Code:
    jar cvfm Clock.jar Clock.MF *
    Your test folder should now contain five files…one of them being the new clock.jar file. You should be able to double click on the clock.jar, and it will execute. You can also execute this code from the command line by typing (java -jar clock.jar).

    Attached Files Attached Files
    Your thoughts are the architects of your destiny.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Jordan Guest

    Re: Creating an Executable Jar File

    Excellent tutorial. Thank you for the read. +rep

  4. #3
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

    Re: Creating an Executable Jar File

    nice tutorial dude .. !! +rep

  5. #4
    Join Date
    May 2008
    Location
    Hell
    Posts
    3,852
    Blog Entries
    4
    Rep Power
    49

    Re: Creating an Executable Jar File

    Sweet tutorial

  6. #5
    TALucas's Avatar
    TALucas is offline Learning Programmer
    Join Date
    Dec 2008
    Location
    Illinois
    Posts
    92
    Rep Power
    12

    Re: Creating an Executable Jar File

    Thanks guys.....

    This is one of those topics I had to research on my own. Four years of college, and seems like they just taught you the basics.
    Your thoughts are the architects of your destiny.

  7. #6
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Creating an Executable Jar File

    One of the things everyone learns when they get out of college is that they only learned the basics. Most new graduates report that they learned more in the first 6 months of working than they did in 2-4 years of college. Of course, the college classes give a basis for learning in those first 6 months
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    whitey6993's Avatar
    whitey6993 is offline Programming Expert
    Join Date
    Dec 2008
    Posts
    435
    Rep Power
    15

    Re: Creating an Executable Jar File

    Awesome tutorial! Thanks for the post +rep

  9. #8
    shoaibbi's Avatar
    shoaibbi is offline Newbie
    Join Date
    Jan 2009
    Posts
    15
    Rep Power
    0

    Re: Creating an Executable Jar File

    gud
    VIvAcIoUs pAkIsTaNi

  10. #9
    dorothy is offline Newbie
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Re: Creating an Executable Jar File

    nice tutorial! thx a lot!

  11. #10
    anticafe is offline Newbie
    Join Date
    Feb 2009
    Posts
    6
    Rep Power
    0

    Re: Creating an Executable Jar File

    Great tutorial. If you are making mobile game, and install that game via OTA (Over the Air), you must print many info of your game and mobile network here.
    Step 2. Create a manifest file…I’ll call mine Clock.MF. A manifest is basically a file that contains information about the files packaged inside the Jar file. You can create yours using a text editor, just give it a .MF extension. Here’s what needs to go in this manifest file:

+ Reply to Thread
Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a new file in CVS
    By DarkLordofthePenguins in forum General Programming
    Replies: 1
    Last Post: 03-12-2011, 02:17 PM
  2. Intermediate Store Executable (or other kind of file) Inside your Executable and Execute it
    By LuthfiHakim in forum Pascal and Delphi Tutorials
    Replies: 0
    Last Post: 01-23-2011, 12:35 PM
  3. .class file to an executable
    By SankaSL in forum Java Help
    Replies: 2
    Last Post: 09-25-2010, 05:06 AM
  4. Creating a file in FTP through PHP
    By Edvinas in forum PHP Development
    Replies: 2
    Last Post: 06-16-2010, 12:26 AM
  5. Replies: 4
    Last Post: 08-05-2009, 08:32 AM

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