Home Java Example Java Util Creating a JAR file in Java
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Creating a JAR file in Java

Advertisement
This section provides you to the creating a jar file through the java source code by using the jar tool command which is provided by the JDK (Java Development Kit).

Creating a JAR file in Java

     

This section provides you to the creating a jar file through the java source code by using the jar tool command which is provided by the JDK (Java Development Kit). Here, you can learn how to use the jar command, which is used in the dos prompt, in the java source code to perform same operations.

Following program is given for best illustration about using the dos used command in the java source code to perform the appropriate tasks. This program has been used the jar command "jar cf jar-file-name directory-name" in the source code to create a jar file for the given directory. You can also specify the file name(s) to collect it into the jar file format.

Code Description:

Runtime:
Runtime is the class of java.lang.*; package of Java. This class helps application to interface with the environment in which the java application is running.

Runtime.getRuntime():
This method gets the current runtime environment.

Runtime.exec(String[] command):
This method helps you to run the command of that environment in which your java application is running.

Here is the code of the program:

import java.io.*;

public class CreateJar{
  public static void main(String[] argsthrows IOException{
  if(args.length <= 0){
  System.out.println("Please enter the command.");
  System.exit(0);
  }
  else{
  Runtime.getRuntime().exec(args[0" " 
  + args
[1" " + args[2" " + args[3]);
  }
  }
}

Download this example.

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 16, 2007

Ask Questions?    Discuss: Creating a JAR file in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
devesh kumar singh
April 21, 2011
creating jar file in java

hi i send me creating jar file in java through command promt & jcreater. u mail me plzzz
devesh kumar singh
April 21, 2011
creating jar file in java

hii u send me code for creating jar file in java throug command prompt & jcreater.plz mail me
balaji
May 25, 2011
creating a jar file in java

What are the arguments that needs to be passed from the command prompt to create the jar file.
DMCA.com