[英]Tomcat. Java runtime compile
I create web application where user can input Java source code in input area and send it to server.我创建了 Web 应用程序,用户可以在其中输入 Java 源代码并将其发送到服务器。 After that I create file User.java
(by default this file created in C:\\Tomcat-8.0.36\\bin
) and compile it in runtime through Runtime.getRuntime().exec("javac User.java")
.之后我创建文件User.java
(默认情况下,这个文件在C:\\Tomcat-8.0.36\\bin
)并在运行时通过Runtime.getRuntime().exec("javac User.java")
编译它。 It's successfully compile.它编译成功。 Then I try to run in Runtime User.class
through Runtime.getRuntime().exec("java User")
, but I get error message: "Could not find or load main class User"
.然后我尝试通过Runtime.getRuntime().exec("java User")
在 Runtime User.class
中运行,但我收到错误消息: "Could not find or load main class User"
。 Although I can correct run this file with the help of cmd of this directory C:\\Tomcat-8.0.36\\bin
.虽然我可以在这个目录C:\\Tomcat-8.0.36\\bin
的 cmd 的帮助下正确运行这个文件。 Also I try to run bat file from code (for example mspaint - successfully run paint - it is mean that correct workspace), but when I run bat file with " java User
" - it is failed.此外,我尝试从代码运行 bat 文件(例如 mspaint - 成功运行 Paint - 这意味着正确的工作区),但是当我使用“ java User
”运行 bat 文件时 - 它失败了。
Any ideas?有任何想法吗? Thanks.谢谢。
Perhaps you should try "java -cp . User" that why you're making sure that User class is on classpath - by -cp .也许您应该尝试“java -cp . User”,这就是为什么您要确保 User 类在类路径上 - 通过 -cp 。 you're putting current folder on the cp.您将当前文件夹放在 cp 上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.