在jar文件中执行shell脚本。如何提取? [英] Executing a shell script inside a jar file. How to extract?

查看:271
本文介绍了在jar文件中执行shell脚本。如何提取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个仅支持Linux的Java应用程序,我需要在其中执行一个shell脚本。根据我所读到的,执行该shell脚本的唯一方法是从jar文件中提取并执行它。问题是?如何在运行时提取该shell脚本?

I am developing a Linux-only Java application, and I need to execute a shell script in it. According to what I have read, the only way to execute that shell script is by extracting it from the jar file and executing it. The question is? How can I extract that shell script at runtime?

提前谢谢

推荐答案

Unix不知道如何在jar文件中运行脚本。您必须使用给定内容创建一个文件(有运行时创建临时文件的例程),然后运行该文件 - 请参阅如何从Java代码运行Unix shell脚本?获取指令。完成后,将其从文件系统中删除。

Unix does not know how to run scripts inside jar files. You must create a file (there are routines to create temporary files in the runtime) with the given content and then run that file - see How to run Unix shell script from Java code? for instructions. When done, delete it from the filesystem.

这篇关于在jar文件中执行shell脚本。如何提取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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