使用java Runtime对象执行maven引入的jar文件
我有一个运行 jar 文件的 java 代码。为此,我使用运行时对象并创建一个如下进程:
Runtime re = Runtime.getRuntime();
Process jarProcess = re.exec(new String[]{"java","-jar","src/resources/myjar.jar"});
当我将 jar 文件放入 src/resources/myjar.jar
中时,该过程完美运行。现在我想改进这一点,而不是将 jar 文件放入资源中,而是想在 .pom 文件中添加对该 jar 的依赖项,然后使用 maven 引入的 jar 文件。但我不知道如何做这个。似乎即使当我硬编码我的 Maven 远程目录(类似于 ~/.m2/... )时,该进程也无法运行。我没有收到任何错误(除非我遗漏了某些内容),但 jarProcess.exitValue()
是 1。那么我如何更新我的代码以引用并执行拉入的 jar 文件由马文。
I have a java code that runs a jar file. To do that I am using the runtime object and create a process like:
Runtime re = Runtime.getRuntime();
Process jarProcess = re.exec(new String[]{"java","-jar","src/resources/myjar.jar"});
This works perfectly when I put my jar file in src/resources/myjar.jar
. Now I want to improve this and instead of putting the jar file in the resources, I want to add a dependency to that jar in my .pom file and then use the jar file that maven pulls in. But I don't know how to do this. It seems that even when I hardcode my maven remote directory which is something like ~/.m2/... the process cannot be run. I don't get any error (unless I'm missing something) but the jarProcess.exitValue()
is 1. So how can I update my code to refer and execute the jar file which is pulled in by Maven.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论