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



Home Answers Viewqa Java-Beginners How to create a jar file
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Vishal Dhole
How to create a jar file
1 Answer(s)      2 years and 5 months ago
Posted in : Java Beginners


Hello!!!! I have a project which has a multiple classes with database connection(MS-Access) & now i want to make a single executable jar of it... so pls tell me how it will b possible for me???


Advertisement
View Answers

July 19, 2012 at 10:29 AM


The given code creates a jar file using java.

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://Answers//Examples");
      File[] files = folder.listFiles();
    File file=new File("C://Answers//Examples//Examples.jar");
    jar.createJarArchive(file, files);
  }
}


Related Tutorials/Questions & Answers:
How to create a jar file
How to create a jar file  Hello!!!! I have a project which has... a single executable jar of it... so pls tell me how it will b possible for me???   The given code creates a jar file using java. import java.io.*; import
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... that you want to create a JAR file. * The f option indicates that you want
Advertisements
How to create a jar file with database connection
How to create a jar file with database connection  Hello Everyone... access & i want to create a jar file of it... I have tried with manifest file but its not working pls help me.....   The given code creates a jar
how to create a jar file for my packages classs - Struts
how to create a jar file for my packages classs  how to create a jar file for my packages classs in struts application .we don't want to see the see the classes other persons
How to Create Jar File using Java
How to Create Jar File using Java Programming Language A Jar file combines... in the jar file.  In this section, we are going to create our own jar file... is to be combined and the path of jar file where we want to create the jar file. Here
how to create a jar file for java classes? - Java Interview Questions
how to create a jar file for java classes?  I have 2 classes x1 and x2. packages names are com.bank.xyz; how to create a jar file for classes.  Hi Friend, Please visit the following link: http
Create JAR file - Java Beginners
Create JAR file  Respected Sir, I got the answer from your side. But do let me know, isn't there any other way of making a JAR File. Simply like... to make a JAR file and run it easily on any computer. For that purpose i want
jar file
jar file  how to create a jar file in java
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
jar file
jar file  steps to create jar file with example
How to use JAR file in Java
) To create a JAR file type "jar cf jar-file input-file(s)" in command prompt. "c" parameter means that you want to create a jar file and "f" parameter means... to digitally sign the JAR file. Users who want to use the secured file can check
jar file
jar file  how to run a java file by making it a desktop icon i need complete procedur ..through cmd
jar file
jar file  jar file where it s used
how can i export a .jar file include .mbd file?
how can i export a .jar file include .mbd file?  i have a project... a error that can't export .jar file width the .mdb file ? how can i import this .mdb file width the .jar file? and how can i run this file on the other computer
JAR FILE
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
how to create ipa file
how to create ipa file  Hi, How to .ipa file? Thanks   Hi, Please check the thread Resources have been modified iPhone. Thanks
jar file - Java Beginners
file. what is the manifest file, and how to create it. And tell me more about... create a JAR file, it automatically receives a default manifest file. There can.../MANIFEST.MFWhen you create a JAR file, the default manifest file simply contains
I want simple steps to create Jar File of Java Project - Java Beginners
I want simple steps to create Jar File of Java Project  Hello Sir How I can Create Jar File of Java Project,plz Help Me  Hi Friend...: Examples>manifest.txt 6. Create a jar file: C:\examples> jar
how to delete a jar file from mobile by using j2me program.
how to delete a jar file from mobile by using j2me program.  When i'll update a new version jar in mobile. Then i want to delete that old jar which is previously present in mobile. How to do
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
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
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
Java Execute Jar file
the classes into one JAR file, we make it portable that can be run anywhere and on any operating system or platform. To execute a JAR file, one must have Java... step is to make the JAR file executable. All class files of the application
Running Jar file in Windows
Running Jar file in Windows  Running Jar file in Windows
How to Unjar a Jar file in Java
to a specified folder. In the same way a user can create a JAR file. JAR files...A JAR file is a collection of Java class files that contains images, methods.... JAR file in Java simplifies distribution and makes it available across
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
How To Make Executable Jar File For Java P{roject - Java Beginners
How To Make Executable Jar File For Java P{roject   Hello Sir I want Help to make Executable File for java Project How I can Make it?  Hi...(); System.out.println("Jar File is created successfully."); } catch (Exception ex
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
How to create XML file - XML
How to create XML file  Creating a XML file, need an example. Thanks!!  To create XML file you need plain text editor like note pad. After... language has many API's to create xml file from program.Here is the code example
jar File creation - Swing AWT
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 creation  I am creating my swing applications. How can i
How To Create a New File
How To Create a New File In this section we will discuss about how to create... which will demonstrate you about how to create a new file in Java... store String, characters, numbers etc. In Java to create a File for storing
 

 

 

DMCA.com