Java Programing laungage

java.util Projects

java.util Project 1

JAR File Creation

In this part of the programming tutorials, we are going to 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, we can learn how to use the jar command, which is used in the dos prompt, in the java source code to perform same operations.

Previous Home Next
adplus-dvertising

In This program we are going to use the jar command "jar cf jar-file-name directory-name" in the source code to create a jar file for the given directory. we 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. This class is used to help application to interface with the environment in which the java application is running.

Runtime.getRuntime()

This methodis used to get the current runtime environment.

Runtime.exec(String[] command)

This method is used to help us to run the command of that environment in which our java application is running.

Example


package r4r;
import java.io.IOException;
import java.util.*;
public class jarcreatetest {
public static void main(String[] args) throws 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]);
}
}
}

Previous Home Next