Creating JAR File



Share on Google+Share on Google+

Creating JAR File
1 Answer(s)      8 years ago
Posted in : Java Beginners
View Answers

October 20, 2009 at 1:47 PM

Hi Friend,

Try the following code:

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("Adding " + listFiles[i].getName());
JarEntry addFiles = new JarEntry(listFiles[i].getName());

FileInputStream fin = new FileInputStream(listFiles[i]);
while (true) {
int len =, 0, b.length);
if (len <= 0)
out.write(b, 0, len);
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);




Related Tutorials/Questions & Answers:
Creating an executable jar file
Creating an executable jar file  When I try to create jar.exe through CMD, the manifest file created doesn't contain Main-Class attribute, even though it is included in text file used during creation of jar file
creating a jar file - JSP-Servlet
creating a jar file  Can you give me detail answer 1. i am having a servlet.class file in classes folder 2. web.xml file my questions are 1. where to place the html or jsp files 2. how to create a jar file and how can
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, I would like you to please help me, in letting me know, as to how to create JAR file from my JAVA source...(); } out.close(); fout.close(); System.out.println("Jar File
Creating JAR File - Java Beginners
Creating JAR File  Respected Sir, Thankyou very much for your... to change the contents of my manifest file. I read somewhere regarding i have to add a line to my manifest file (i.e. Main-Class: mypackage.MyClass
Creating a JAR file in Java
Creating a JAR file in Java       This section provides you to the creating a jar file.... This program has been used the jar command "jar cf jar-file-name directory
jar file
jar file  steps to create jar file with example
jar file
jar file  how to create a jar file in java
jar file
jar file  jar file where it s used
JAR FILE  WHAT IS JAR FILE,EXPLAIN IN DETAIL?   A JAR file... and applications. The Java Archive (JAR) file format enables to bundle multiple... link: Jar File Explanation
creating JAR - Java Beginners
creating JAR  I am beginner in J2ee.I am creating an application... installed SQL and Tomcat.I created a JAR of my java project and included... JAR to the lib, the WEBAPPlication libraries doesnot reflect the new class added
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
jar file - Java Beginners
jar file  jar file When creating a jar file it requires a manifest... options in jar file. What is Jar File? JAR files are packaged in the zip format  What is Jar File?JAR files are packaged in the zip format making
Running Jar file in Windows
Running Jar file in Windows  Running Jar file in Windows
File path for jar file
File path for jar file  Hi Experts, I have created one eclipse... jar file of that application, unfortunately it is giving the error that resource not found for the template file. Also I had tried to get that path from user
Extract Jar File
Extract Jar File  How to extract jar file?   Hi Please open the command Prompt and to the jar file and write the command jar -xvf JaraFileName.jar
org.apache.commons.collections15.Transformer jar file
org.apache.commons.collections15.Transformer jar file  Dear, Please can you provide me the link for the following jar file: import org.apache.commons.collections15.Transformer; tahnks too much
jar File creation - Swing AWT
jar File creation  I am creating my swing applications. How can i... in java but we can create executable file in java through .jar file.. how can i convert my java file to jar file? Help me
jar file with html
jar file with html  I have a jar file. On double click it shows an applet page. Please tell me how to connect that applet into html or jsp page
JAR File - Swing AWT
JAR File   Is there anybody to solve my problem of not executing the JAR file? I have asked the question previously but I haven't got any answer yet. Please help me
Jar file - Java Beginners
Jar file  Hello this is my second question and i hope atleast i will get answer i bulid a jar file of my project using netbeans but now problem is when i open that jar file in command prompt i got error exception in thread
change jar file icon - Java Beginners
change jar file icon  How to create or change jar file icon  Hi friend, The basic format of the command for creating a JAR file is: jar cf jar-file input-file(s) * The c option indicates that you want
How to create a jar file
???   The given code creates a jar file using java. import*; import...(); System.out.println("Jar File is created successfully."); } catch (Exception ex...How to create a jar file  Hello!!!! I have a project which has
Java Jar File - Java Beginners
Java Jar File  What is a Java JAR file ..and how can i open a .jar file in Java?  Just create a Jar file and Double click on it, it will automatically runs main method in that Jar : to create Project as JAR
conversion of war file into executable jar file
conversion of war file into executable jar file  how to convert war file into executable jar file
What is a JAR file in Java
What is a JAR file in Java       JAR file is the compressed file format. You can store many files in a JAR file. JAR stands for the Java Archive. This file format is used
Creating a setup file
Creating a setup file  How to create a setup file in tomcat as done in visual studio... could plz tell me as early as possible
Apache HSSF Jar file location
Apache HSSF Jar file location  where can i get jar files for apache hssf
Creating XMl file - XML
Creating XMl file   I went on this page: and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
creating a file in a directory
creating a file in a directory  hi i have tried all the file methods to create a file inside a directory but none of them r working some of them are new File ( ".", "C:/fileInRoot.txt" ) new File ( "myDir", "/otherDir" ) File
how to convert a jar file into .exe file
how to convert a jar file into .exe file  hi, I want convert my jar file into executable file,urgently please help me
how can create a jar file - Java Beginners
how can create a jar file  plz any one help me which file can i create the jar file plz give exact command  Hi The basic format of the command for creating a JAR file is: jar cf jar-file input-file(s


Advertisement null