creating jar using java.util.jar

Discussions

General J2EE: creating jar using java.util.jar

  1. creating jar using java.util.jar (2 messages)

    Greetings..!

    I am using java.util.jar.* to create a jar file from Java code. It is creating the file properly with an empty manifest file. But, when I load this JAR into the application server the server is not recognizing it. If I use the same set of files and create a JAR file using the jar -cvf command at dos prompt and load it into application server it recognizes it. What could be the problem?

    Both Jar files are having same set of files, same size except the manifest.mf file.

    Following is the code that I am using.


    final int BUFFER = 2048;
    Manifest man=new Manifest();
    BufferedInputStream origin = null;
    File f = null;
    String[] files = null;
    FileOutputStream dest = new FileOutputStream("Adv-Rep.jar");
    JarOutputStream out = new JarOutputStream(new BufferedOutputStream(dest),man);
    byte[] data = new byte[BUFFER];
    f = new File("class-files" + seperator + "org" +
    seperator + "mirapoint");
    files = f.list();

    for (int i = 0; i < files.length; i++) {
    System.out.println("Adding: " + files[i]);

    FileInputStream fi = new FileInputStream("org" + seperator +
    "mirapoint" + seperator + files[i]);


    origin = new BufferedInputStream(fi, BUFFER);

    JarEntry entry = new JarEntry("org" + seperator + "mirapoint" +
    seperator + files[i]);
    out.putNextEntry(entry);

    int count;

    while ((count = origin.read(data, 0, BUFFER)) != -1) {
    out.write(data, 0, count);
    }

    origin.close();
    }

    f = new File "META-INF");


    files = f.list();

    for (int i = 0; i < files.length; i++) {
    System.out.println("Adding: " + files[i]);

    FileInputStream fi = null;
    fi = new FileInputStream("META-INF" +
    seperator + files[i]);
    }

    origin = new BufferedInputStream(fi, BUFFER);

    JarEntry entry = new JarEntry("meta-inf" + seperator + files[i]);
    out.putNextEntry(entry);

    int count;

    while ((count = origin.read(data, 0, BUFFER)) != -1) {
    out.write(data, 0, count);
    }

    origin.close();
    }

    out.close();
    flag=true;


    How to create a perfect JAR file thru JAVA code? What must be the Manifest.mf entries?

    Thanks in Advance..!

    Kala.

    Threaded Messages (2)

  2. Facing the same issue[ Go to top ]

    I am also having the same issue. Does anybody knows why it's not working? Thanks - Deepak Jaju
  3. Look on Sun blog[ Go to top ]

    Well, this thread is kind of old, so I suspect that you've already solved your problems but, just in case someone lands on this page looking for how to make jar file... look in this address, may help you get started. http://blogs.sun.com/CoreJavaTechTips/entry/creating_zip_and_jar_files