简体   繁体   中英

Adding files to an existing jar file in java

I need some help with using the following code to modify and existing jar file:

    String command = "cmd /c jar uf " + dirToModify + " " + Main.getMain().outputLocate.getSelectedFile();
    try {
        Runtime.getRuntime().exec(command);
    } catch (IOException e) {
        e.printStackTrace();
    }

    dirToModify = "C:\\Users\\Me\\Desktop\\myfile.jar"
    Main.getMain().outputLocate.getSelectedFile() = "C:\\Users\\Me\\Desktop\\myfolder"

Basically I want to add the files/folders from myfolder to myfile.jar but with the above code it will add a shortcut to my C: drive not the files from myfolder .

Also I did look at other posts but none help me with this problem.

Any help with this would be greatly appreciated.

I'd suggest, first checking, if adding one file, at a time, is working with this code. This will make clear if problem is in 'folder addition' or 'file addition'. If file addition doesn't work, your basic jar update logic is broken. So you can ask for solution to that problem. If file addition works, try recursively adding all files from destination folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM