How to execute script from JAR file?

前端 未结 3 1114
醉酒成梦
醉酒成梦 2020-12-19 17:55

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 exe

相关标签:
3条回答
  • 2020-12-19 18:06

    File inside jar is no longer a file, So to execute it you first need to extract it somewhere and then execute it from external extracted file path

    0 讨论(0)
  • 2020-12-19 18:13

    I would do the following:

    • Get InputStream for the file with ClassLoader.getResourceAsStream()
    • Write this InputStream to tmp dir
    • Execute it with Runtime.getRuntime().execute(..)
    0 讨论(0)
  • 2020-12-19 18:19

    You will need to extract the script from the jar file:

    jar -xvf my.jar com/foo/my.script.sh
    
    0 讨论(0)
提交回复
热议问题