how to create .exe file of java application??

how to create .exe file of java application??

View Answers

July 30, 2009 at 10:05 AM

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("-----------------------------------");
System.out.println("Adding " + listFiles[i].getName());
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://Answers//Database";);
File[] files = folder.listFiles();
File file=new File("C://Answers//DataBase//DataBaseExamples.jar";);
jar.createJarArchive(file, files);
}

}

Thanks

June 22, 2012 at 12:35 AM

Thanks Dear,

I tested the program and it's running without any error ....

Pramoj









Related Tutorials/Questions & Answers:
how to create .exe file of java application?? - Java Beginners
To make java exe or runnable file
Advertisements
creating an .exe file - Java Beginners
how to convert war file into .exe file using java code
how to run a .exe file in jsp
how to call an exe file from java - Java Beginners
how to convert a jar file into .exe file
set java exe file as background - Java Beginners
how to start intergrated webcam of a laptop without calling its exe file using java only - Java Beginners
exe file creation - JDBC
Creating an exe file
How to convert many class files into one exe file?
How to convert many class files into one exe file?
Server calling of .exe file in the client
conerting web project into .exe file
how to create an excel file using java
how to create pdf file using java and itextjar
how to create pdf file using java and itextjar
how can create a jar file - Java Beginners
how to create ipa file
How to create a jar file
How to embedd jre inside the converted .exe file from .jar using Launch4J
How To Create a New File
Create File in Java
.EXE - Java Beginners
How to create XML file - XML
how to create tar file in ubuntu
how to create tar file in ubuntu
HTML EXE FILE Creater - Development process
how to create a jar file for java classes? - Java Interview Questions
Java MappedByteBuffer example, How to create a large size file in java.
how to create a set up file of java web application
how to create a set up file of java web application
how to create a set up file of java web application
.Exe - Java Beginners
How to Create Jar File using Java
we can create our own header file in java?n how to create?
how to convert jsp to exe
Java file create new file
Invoking exe - Java Beginners
Create new file in java
CREATE AND WRITE FILE THREAD JAVA
How to create a new text file that contains the file names of the copied files in a new directory? - Java Beginners
Create JAR file - Java Beginners
How to create pdf file in struts2.
how to create a php script to download file
How to create file from input values in Jframe ?
How to create a jar file with database connection
How to create a .mdf file from script (.sql)
how to create an xml file in following clear format

Ads