简体   繁体   中英

Unable to execute java jar from another java file

I have an eclipse plugin project and I need to execute and external jar from the project. The jar file is in the src folder of my project. Can some one help me how to execute the jar from within the project? This is the code I have

startJar.java:
    ProcessBuilder pb = new ProcessBuilder("java", "-jar","MyJar.jar");
    pb.start();

It doesn't work.startJar.java and MyJAr.jar are in the same folder. Help?

There is a problem it is in src folder, it should be in bin folder

If you want to let it in src folder, you have to change path like this:

String path = ".."+File.separator+"bin"+File.separator+"MyJar.jar";
ProcessBuilder pb = new ProcessBuilder("java", "-jar",path);
pb.start();

It looks like this (/ or \\ depends on OS):

../bin/MyJar.jar

Note: much better will be moving .jar file into bin 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