用于在mac

时间:2016-01-20 10:06:48

标签: java macos shell

有没有办法使用shell脚本在mac上添加adb路径和apppium路径?或者是否有一个java代码在mac上设置路径?

我已经看到了一个与此相关的问题(这里是set windows PATH environment variable at runtime in Java)但是它适用于Windows。有人可以帮我在mac上工作

我正在使用此代码但仍未改进。我可以设置windows环境变量而不是mac。

public static void testProcessBuilder(String path) throws IOException {
        //export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.3.3
        //export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
        String[] args = new String[] {"/bin/bash", "-c", "export "+"JAVA_HOME=/Library/Java/Home"};
        ProcessBuilder processBuilder = new ProcessBuilder(args);
        Process p = processBuilder.start();
        String line;
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = r.readLine()) != null) {
            System.out.println(line);
        }
        r.close();
    }

1 个答案:

答案 0 :(得分:0)

 String[] args = new String[] {"/bin/bash", "-c", "export "+"JAVA_HOME=/Library/Java/Home"};

将上一行替换为此行

String[] args = new String[] {"/bin/bash", "-c","-l" "echo \"export JAVA_HOME=$(/usr/libexec/java_home)\" >> ~/.bash_profile;source ~/.bash_profile"};