如何在Java代码中执行外部的JAR文件?

huangapple go评论59阅读模式
英文:

How can I execute an external jar in java code?

问题

<br>
我有一个外部的Java jar文件,它可以将基于文本的格式渲染成一个以png文件形式呈现的图形。为了在web中使用这个功能,我创建了一个Spring webservice。在一个post方法中,这个服务会接收文本格式的数据。我该如何在Spring控制器中调用外部的jar文件并使用结果呢?
Runtime.getRuntime().exec("java -jar renderer.jar -p")?我该如何将文本格式的数据传递给这个命令,并且我需要将外部jar文件放在什么位置呢?<br>
提前感谢您的帮助!

英文:

<br>
I have a external Java jar, which renders a textbased format into a graph as png file. To use this functionality in web, I created a spring webservice. In a post method, the service receives the textbased format. How am I able to call the external jar in the spring controller and use the result?
Runtime.getRuntime().exec(&quot;java -jar renderer.jar -p&quot;)? How can i pipe the textbased format in the command and where do I have to place the external jar?<br>
Thanks in advance!

答案1

得分: 1

你应该将 renderer.jar 作为依赖项包含在你的 Spring 项目中。然后你可以使用该 jar 包中的类。

你的项目管理工具是什么?例如,Maven 可以让你创建本地构件(如果 renderer.jar 不是一个公共库的话)。

英文:

You should include renderer.jar into you spring project as dependency. Then you could use classes from that jar.

What is you project management tool? Maven for example allow you to create local artifact (if renderer.jar is not a public library).

huangapple
  • 本文由 发表于 2020年9月16日 23:02:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63922859.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定