是否有可能激发一个可执行文件,以便它可以从Java运行? [英] Is it possible to jar up an executable so that it can be run from Java?
问题描述
ProcessBuilder
)。 为什么是我想使用ImageMagick可执行文件的Java包装器作为图像处理Elastic Map Reduce作业的组件。 EMR只希望得到一个jar文件,所以我认为没有任何空间可以在启动数据节点上安装软件。 解决方案
到jar中的可执行文件是一个资源,您可以通过Stream访问它,并将可执行文件扩展到TEMP目录,然后使用ProcessBuilder执行。
File target = new File(System.getProperty(java.io.tmpdir),< filename>);
InputStream is =
getClass()。getClassLoader()。getResourceAsStream(< path to rc>);
OutputStream os = new FileOutPutStream(target);
>
进程p = new ProcessBuilder(target).start();
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.
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();
这篇关于是否有可能激发一个可执行文件,以便它可以从Java运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!