无法使用Runtime.getRuntime()。exec从jsp执行java程序 [英] Unable to execute java program from jsp using Runtime.getRuntime().exec

查看:458
本文介绍了无法使用Runtime.getRuntime()。exec从jsp执行java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过jsp运行一个jar文件。我使用命令 Runtime.getRuntime()。exec(java -jar file.jar); 我收到错误无法访问jarfile文件.jar 当我打印错误流时。

I am trying to run a jar file through jsp. I use the command Runtime.getRuntime().exec("java -jar file.jar"); I get the error Unable to access jarfile file.jar when I print the error stream.

我尝试使用设置为当前目录的类路径运行为 Runtime.getRuntime()。exec(java -cp.-jar file。 jar); 但仍然得到相同的错误。我也试过给jar文件的整个路径。当我这样做时,jsp文件在执行exec语句后挂起。

I tried running with the classpath set to the current directory as Runtime.getRuntime().exec("java -cp . -jar file.jar"); but still get the same error. I also tried giving the entire path to the jar file. When I do this, the jsp file hangs after execuing the exec statement.

这是我在windows中使用的行:

This is the line I use in windows:

process = Runtime.getRuntime().exec("java -jar C:\\Users\\Jeff\\Documents\\NetBeansProjects\\WebApplication1\\file.jar");

我使用文章但仍有相同的问题(挂起)。有人可以帮忙吗?

I use the streamgobbler thing given in the article but still have the same problem (hangs). Can someone help?

推荐答案

它永远不会有效。否则就会出现安全漏洞。想象一下,您可以从Web浏览器运行任何可执行文件......您应该将您的类放在服务器上,让它们可以访问您的jsp,然后从jsp运行一些方法。

It will never work. Otherwise it would be security breach. Imagine that you could run any executable from web browser... You should put your classes on server, make them accessible to your jsp and then run some method from jsp.

这篇关于无法使用Runtime.getRuntime()。exec从jsp执行java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆