Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How To Make Executable Jar File For Java P{roject
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sushant
How To Make Executable Jar File For Java P{roject
3 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners


Hello Sir I want Help to make Executable File for java Project How I can Make it?

Advertisement
View Answers

February 24, 2010 at 12:59 PM


Hi Friend,

Try the following code:

import java.io.*;
import java.util.jar.*;

public class CreateJar {
public static int buffer = 10240;
protected void createJarArchive(File jarFile, File[] listFiles) {
try {
byte b[] = new byte[buffer];
FileOutputStream fout = new FileOutputStream(jarFile);
JarOutputStream out = new JarOutputStream(fout, new Manifest());
for (int i = 0; i < listFiles.length; i++) {
if (listFiles[i] == null || !listFiles[i].exists()|| listFiles[i].isDirectory())
System.out.println();
JarEntry addFiles = new JarEntry(listFiles[i].getName());
addFiles.setTime(listFiles[i].lastModified());
out.putNextEntry(addFiles);

FileInputStream fin = new FileInputStream(listFiles[i]);
while (true) {
int len = fin.read(b, 0, b.length);
if (len <= 0)
break;
out.write(b, 0, len);
}
fin.close();
}
out.close();
fout.close();
System.out.println("Jar File is created successfully.");
} catch (Exception ex) {}
}
public static void main(String[]args){
CreateJar jar=new CreateJar();
File folder = new File("C:\\html");
File[] files = folder.listFiles();
File file=new File("C:\\html\\Examples.exe");
jar.createJarArchive(file, files);
}

}

Thanks


February 24, 2010 at 2:41 PM


visit this page this contains step by step guide
http://csdl.ics.hawaii.edu/~johnson/613f99/modules/04/jar-files.html


February 24, 2010 at 2:55 PM




Related Tutorials/Questions & Answers:
 

 

 

DMCA.com