Is it possible to jar up an executable so that it can be run from Java?

你。 提交于 2019-12-19 09:25:21

问题


Simply put, I need to be able to stick a compiled executable inside a Java jar file and then be able to run it from Java (probably via ProcessBuilder).

The why, is that I would like to use a Java wrapper around the ImageMagick executable as component of an image processing Elastic Map Reduce job. EMR only expects to take a jar file, so I don't think there's any room to install software on the data nodes that spin up.


回答1:


The executable into the jar is a resource, you may access it via a Stream and expand the executable to the TEMP directory, then execute it with ProcessBuilder.

File target = new File( System.getProperty( "java.io.tmpdir" ), <filename> );
InputStream  is =
   getClass().getClassLoader().getResourceAsStream( <path to rc> );
OutputStream os = new FileOutPutStream( target );
<copy is to os>
Process p = new ProcessBuilder( target ).start();


来源:https://stackoverflow.com/questions/15910235/is-it-possible-to-jar-up-an-executable-so-that-it-can-be-run-from-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!