我的系统中有 Java 7 作为默认配置。但是我必须仅在春季启动时使用 Java 8。以下命令在我的终端中运行良好。ubuntu@karthick:~$ JAVA_HOME=/opt/jdk1.8.0_181 mvn spring-boot:run但是当我尝试从 Process Builder 执行它时,它显示错误。代码:ProcessBuilder pb = new ProcessBuilder("JAVA_HOME=/opt/jdk1.8.0_181", "mvn", "spring-boot:run");pb.directory(new File("/home/ubuntu/project/springbootexample"));Process p = pb.start();我收到以下错误error=2, No such file or directory. Stacktrace follows:java.io.IOException: error=2, No such file or directory at java.lang.UNIXProcess.<init>(UNIXProcess.java:135) at java.lang.ProcessImpl.start(ProcessImpl.java:130) at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022) ... at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198) at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:150) at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:281) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:202) at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:180) at com.brandseye.cors.CorsFilter.doFilter(CorsFilter.java:82) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)如何解决问题?
1 回答
守候你守候我
TA贡献1802条经验 获得超10个赞
我建议创建一个脚本文件(下面的 test.sh),您可以在其中设置 java home 并添加其他命令来运行 spring boot 并使用以下代码从 java 调用该脚本:
String[] args = { "/bin/bash", "test.sh"};
StringBuilder builder = new StringBuilder();
Process p2 = null;
String result = null;
String[] cmd = { "sudo", "-s" };
Runtime.getRuntime().exec(cmd);
p2 = Runtime.getRuntime().exec(args);
BufferedReader reader = new BufferedReader(new
InputStreamReader(p2.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
result = builder.toString();
添加回答
举报
0/150
提交
取消