Jar stands for Java archive. It's nothing but a compressed zip file which contains all files and folders related to your java program whether it is image, package, class file or anything else.It helps programmer pack file in one file and reduce the size of project.A jar file can be executable.
Jar file can be created using a utility comes with jsdk called jar. You can find it in <Your Java sdk path>\bin folder as jar.exe in Windows.
Here is simple steps to create a jar file of your java project.
Suppose i have a source file called P3.java.
Now follow steps given below :
Step 1. Compile your java source into .class file. My class file is P3.class
Step 2. Now create a file called prg.MF known as manifest file that contains following entries using notepad.
Created-By: 1.2 (Sun Microsystems Inc.)
Manifest-Version: 1.0
Main-Class: P3
In above entries first line tells the version and the vendor of Java implementation.
Second line indicates that our manifest file conforms to the specification version 1.0
Third line describes a name of class file in which main function resides.
Step3. Now the third and final step. Go to command prompt and execute jar utility as described below.
jar cvfm Prog.jar prg.MF *
Here c,v,f,m are different options of jar utility.
c - Creates a new file
v - Generates verbose output to screen (You can omit this option)
f - Specifies archive file name
m - Includes information from our own manifest file
Prog.jar is our archive file name.You can specify any name.
prog.MF is a manifest file created by us.
* indicates that all file should be included in archive.
Check folder for generated Prog.jar and execute it.
Monday, December 6, 2010
Friday, December 3, 2010
Program that will demonstrate the use of object serialization with different write methods
/* Program : 1
Create an application that will demonstrate the use of object serialization with different write methods
Developed by : Malhar Vora
Developed on :6-11-2010
Development Status : Completed and tested
Email : vbmade2000@gmail.com
WebSite : www.malhar2010.blogspot.com
********************************************************************************/
import java.io.*;
public class P1
{
public static void main(String []str)
{
ReadWriteData rwdata = new ReadWriteData();
rwdata.writeData("test1.txt");
rwdata.readData("test1.txt");
}
}
class ReadWriteData
{
public void writeData(String fname)
{
FileOutputStream fos = null;
ObjectOutputStream oos = null;
try{
fos = new FileOutputStream(new File(fname));
oos = new ObjectOutputStream(fos);
oos.writeInt(10);
oos.writeUTF("Hello World");
}
catch(Exception e)
{
}
finally
{
try
{
oos.close();
fos.close();
}
catch(Exception e)
{
;
}
}
}
public void readData(String fname)
{
FileInputStream fis = null;
ObjectInputStream ois = null;
try{
fis = new FileInputStream(new File(fname));
ois = new ObjectInputStream(fis);
System.out.println("Integer " + ois.readInt());
System.out.println("String " + ois.readUTF());
}
catch(Exception e)
{
;
}
finally
{
try
{
ois.close();
fis.close();
}
catch(Exception e)
{
;
}
}
}
}
Subscribe to:
Posts (Atom)