Permission denied when running shell script from j

2019-05-25 21:36发布

问题:

I am trying to run my shell script using java program. I am getting following exception.

java.io.IOException: Cannot run program "/home/builder/code/target/classes/idFetcher.sh": java.io.IOException: error=13, Permission denied
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
    at java.lang.Runtime.exec(Runtime.java:605)
    at java.lang.Runtime.exec(Runtime.java:443)
    at java.lang.Runtime.exec(Runtime.java:340)
    at script.InformationFetcher.main(InformationFetcher.java:26)

The path of file is correct and file is present at that location. Here is my code

package script;

import java.io.IOException;

public class InformationFetcher {

    public InformationFetcher() {
    }

    public static void main(String[] args) {
    try {
        InformationFetcher informationFetcher = new InformationFetcher();
        Runtime.getRuntime().exec(informationFetcher.getFilePath());
    } catch (IOException e) {
        e.printStackTrace();
    }

    }

    public String getFilePath() {
    return this.getClass().getResource("/idFetcher.sh").getPath();
    }

}

回答1:

Make the shell script executable for the user



标签: java shell