-2

I have two folders stored inside the jar of my Javafx application, I don't want to distribute this application to customers as a executable jar file, so i have changed it to a Application (.exe) file using Launch4J.

when the user activates the Application (.exe), my application will try to copy the two folders from the Application (.exe) to a certain directory, at the moment I can't seem to be able to reference the two folders inside the .exe.

Does anyone know how to do this in java?

noobCoder
  • 370
  • 1
  • 8
  • 18
  • Instead of giving me a down vote maybe explain to me why you don't think the question is valid or what i'm doing wrong! – noobCoder May 25 '16 at 15:14
  • Did you check http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#BCGIBBCI – Jayan May 25 '16 at 16:13
  • ya i did but that wasn't what i needed, but thanks for the link.I got it working using the code i posted below – noobCoder May 25 '16 at 16:15

1 Answers1

0

here is the code i used to make this work, which i found on this page if anyone ever needs it. How to write a Java program which can extract a JAR file and store its data in specified directory (location)?,

    String temp  = System.getProperty("user.dir") + "\\unzipTester.exe";
    String destDir = "C:\\Users\\chris\\Desktop\\New folder (2)";
    java.util.jar.JarFile jar = null;

    try{
    jar = new java.util.jar.JarFile(temp);
    }
    catch(Exception ex){
        JOptionPane.showMessageDialog(null,ex.getMessage());
    }
    //JOptionPane.showMessageDialog(null,jar.getName());
    java.util.Enumeration enumEntries = jar.entries();
    while (enumEntries.hasMoreElements()) {
        java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
        if(file.toString().contains("unziptester") || file.toString().contains("MANIFEST.MF") 
                || file.toString().contains("META-INF")){
            continue;            
        }
        System.out.println(file.toString());
        java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
        if (file.isDirectory() && !file.toString().contains("unziptester") && !file.toString().contains("META-INF")) { // if its a directory, create it
            f.mkdir();
            continue;
        }
        java.io.InputStream is = jar.getInputStream(file); // get the input stream
        java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
        while (is.available() > 0) {  // write contents of 'is' to 'fos'
            fos.write(is.read());
        }
        fos.close();
        is.close();
    }
Community
  • 1
  • 1
noobCoder
  • 370
  • 1
  • 8
  • 18