如何从JAR文件执行脚本? [英] How to execute script from JAR file?

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

问题描述

我有一个maven项目,其中,我正在尝试执行一个脚本(用R编写)。我也把这个脚本文件放在源代码目录中。我发现这个脚本根本没有执行。但是,当我将此脚本移到jar文件之外时,它会执行!任何人都可以告诉我为什么,并给我一些解决方案将脚本放入jar中,同时确保其执行?

I have a maven project, in which, I am trying to execute a script (written in R). I put this script file in the source code directory as well. I found this script is not executed at all. However, when I move this script outside the jar file, it does execute ! Can anyone tell me why, and give me some solutions to put the script inside the jar while ensure its execution?

非常感谢!

推荐答案

我会做以下事情:


  • 使用ClassLoader.getResourceAsStream()获取文件的InputStream

  • 将此InputStream写入tmp目录

  • 使用Runtime.getRuntime()执行它.execute(..)

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

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