[英]How do I get and run a jar file within a Java program?
I'm creating an operating system-like program in java and have run into a little trouble. 我正在用Java创建类似于操作系统的程序,但遇到了一些麻烦。 I want the user to be able to run jar files of their choice in it, but I don't really know how though. 我希望用户能够在其中运行他们选择的jar文件,但是我真的不知道如何。
Basically, it will work like this: 基本上,它将像这样工作:
You can use the Runtime.exec(String) method for that. 您可以为此使用Runtime.exec(String)方法。
For example: 例如:
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("java -jar yourJar.jar");
Does start your jar
within a running Java program. 是否在正在运行的Java程序中启动jar
。 In your case you have to ensure that the jar yourJar.jar
starts in a JInternalFrame
. 在您的情况下,必须确保jar yourJar.jar
在JInternalFrame
启动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.