简体   繁体   中英

Loading External Jar Files with Java

I'm trying to run a Jar file with this function, but, it ends up saying it can't

java.io.IOException: Cannot run program "C:\\Users\\User\\Documents\\NetBeansProjects\\JavaApplication2\\dist\\JavaApplication2.jar": CreateProcess error=193, %1 is not a valid Win32 application

Is there any other solution that can fit into this function? I'd like to do this externally through a String, I've explored other solutions, but, have found none that work for me.

    private static void runprogram(String path) {
        try {
            Process process = Runtime.getRuntime ().exec(path);
        } catch (IOException ex) {
            Logger.getLogger(Recap.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

It doesn't work since

"C:\\Users\\User\\Documents\\NetBeansProjects\\JavaApplication2\\dist\\JavaApplication2.jar"

is not a valid program to be run.. You should call (or pass as a path argument) this:

java -jar C:\\Users\\User\\Documents\\NetBeansProjects\\JavaApplication2\\dist\\JavaApplication2.jar

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