简体   繁体   中英

ProcessBuilder can't access a relative folder location

I'm trying to execute a third party JAR from Java code using ProcessBuilder . This JAR requires that you must be at the installation directory when executing this JAR, otherwise it will not work. Below is the folder structure for this third party JAR:

C:\\Program Files\\MSG MCE Software I10
C:\\Program Files\\MSG MCE Software I10\\jre
C:\\Program Files\\MSG MCE Software I10\\jre\\bin

Here is the code I'm using:

String cmdLine = "\"jre\\bin\\java\" -Xms512m -Xmx1024m -cp \"C:\\Program Files\\MSG MCE Software I10\\msgmce.jar;C:\\Program Files\\MSG MCE Software I10\\*:.\" com.mmm.his.msgmce.Main -i \"C:\\drginput\\"+inFileName+"\" -o \"C:\\drgoutput\\"+outFileName+"\" ";
ProcessBuilder builder = new ProcessBuilder( "cmd.exe", "/c", "cd \"C:\\Program Files\\MSG MCE Software I10\"&&"+cmdLine);
System.out.println("cmdLine->"+cmdLine); 
Process p = builder.start();

As you can see I initially try to navigate to the installation directory "C:\\\\Program Files\\\\MSG MCE Software I10\\" and then try to execute the java executable file.

Problem is that I'm getting a "System cannot find file specified" because it can't find the relative path of "jre/bin/java" .

Now this works on one machine but not on another machine. When creating the ProcessBuilder and invoking the cmd.exe , I'm navigating to the installation home directory, so I should be able to access the jre/bin/java file.

Does anyone have any idea why this would work on one machine but not another one?

OK I figured this out. On the computer where it was working, all programs like Eclipse, Tomcat were installed on the same C drive, but on the other computer Eclipse was installed on a different drive.

The third party JAR was installed on C drive and my program was running on Eclipse but on the D drive. For some reason the change directory in ProcessBuilder to the C drive was not working. Not sure if this is a limitation of ProcessBuilder for security reasons, but installing everything on a single drive worked.

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