如何从Java执行R脚本文件

时间:2018-12-29 10:51:29

标签: java r rserve jri

我想从Java调用R脚本。我已经对该主题进行了google搜索,但是几乎所有看到的结果都需要我为某些第三方库添加依赖项。谁能向我展示一种在不添加任何依赖项的情况下完成同一件事的好方法?

我正在设置一个新应用程序,该应用程序使用以下行从Java运行R脚本文件

  

Runtime.getRuntime()。exec(“ C:\ Users \ Thiru \ Desktop helloWorld.R”);

但是当我运行应用程序时,出现以下异常:

SEVERE: Servlet.service() for servlet [RenjinServlet] in context with 
path 
[/REngineCheck] threw exception
java.io.IOException: Cannot run program "C:\Users\Thiru\Desktop": 
CreateProcess error=5, Access is denied
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at org.r.Check.RenjinServlet.doGet(RenjinServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at 

org.apache.catalina.core.ApplicationFilterChain.internalDoFilter 
(ApplicationFilterChain.java:291)
at 
org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter 
(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter 
(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke 
(StandardWrapperValve.java:217)
at org.apache.catalina.core.StandardContextValve.invoke 
(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke 
(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke 
(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke 
(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke 
(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke 
(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service 
(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process 
(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process 
(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun 
(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run 
 (NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run 
  (TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: CreateProcess error=5, Access is denied
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 28 more

0 个答案:

没有答案