ajax的后台java类可以调用自己编写的exe文件吗,我在java application中调用就没问题:Runtime rt = Runtime.getRuntime();
String command="calcu-3.exe";
Process proc = rt.exec(command);这样是可以正常运行的,但是在使用ajax后,后台的java类中也是相同的代码,为什么就报错?错误信息:
java.io.IOException: Cannot run program "calcu-3.exe": CreateProcess error=2, ϵͳÕҲ»µ½ָ¶
at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:431)
at java.lang.Runtime.exec(Runtime.java:328)
at healthyrich.calculator.Service.sayHello(Service.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.directwebremoting.impl.ExecuteAjaxFilter.doFilter(ExecuteAjaxFilter.java:34)
at org.directwebremoting.impl.DefaultRemoter$1.doFilter(DefaultRemoter.java:428)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:431)
at org.directwebremoting.impl.DefaultRemoter.execute(DefaultRemoter.java:283)
at org.directwebremoting.servlet.PlainCallHandler.handle(PlainCallHandler.java:52)
at org.directwebremoting.servlet.UrlProcessor.handle(UrlProcessor.java:101)
at org.directwebremoting.servlet.DwrServlet.doPost(DwrServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
请高手指教,谢谢

解决方案 »

  1.   

    找不到文件吧。
    把calcu-3.exe配到系统PATH中再启动Tomcat试试看。
      

  2.   


    谢谢回复,我把exe所在目录加到了PATH里面,
    不过我的这个exe在命令行下面只有cd到它所在的目录它才能运行成功,如果在其它目录下,会出现这样的信息:C:\Users\YTQ>calcu-3.exe
    欢迎您使用计算系统
    I cannot open the source file in output!这个exe是导师给的,我不知道它的实现原理。不过我疑惑的是为什么在java application中可以正常运行,换成ajax后台的java中就不行了呢?exe文件我都是放在项目的根目录下的,难道它们寻找文件的方式不一样?
      

  3.   

    当然不同。你试一下找出Server的当前系统目录:
    在某Servlet或JSP中加入代码System.out.println(System.getProperty("user.home"));找到目录后,将exe文件放此目录中
      

  4.   


    我在jsp中输入System.out.println(System.getProperty("user.home"));控制台显示“C:\Users\YTQ”
    YTQ是我用户名,然后我再将exe放入这个目录中,还是不起作用啊,浏览器中运行,返回的结果是:“欢迎您使用计算系统
    I cannot open the source file in output!”,这个是exe程序自己的错误信息,具体为什么我不大清楚,
    不过,这次我在命令行下输入,就可以了:C:\Users\YTQ>calcu-3.exe
    欢迎您使用"误差可控"计算系统
    请选择(0---弧度, 1---角度, 2--显示函数列表, e---退出):
      

  5.   

    这样的一个程序的话,不知道用CGI技术做是不是更好一些。