是否有可能激发一个可执行文件,以便它可以从Java运行? [英] Is it possible to jar up an executable so that it can be run from Java?

查看:97
本文介绍了是否有可能激发一个可执行文件,以便它可以从Java运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单地说,我需要能够将编译好的可执行文件粘贴到Java jar文件中,然后才能够从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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆