Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute script from JAR file?

Tags:

java

maven

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?

Thanks a lot !

like image 305
Ensom Hodder Avatar asked Feb 20 '23 23:02

Ensom Hodder


1 Answers

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(..)
like image 129
Konstantin Solomatov Avatar answered Feb 26 '23 10:02

Konstantin Solomatov