1

I have one spring boot application which exposes some rest services.It contains some sql files and some python files which are stored in files inside resources folder in folder structure resources/scripts/. Some of them are sql whereas some of them are python scripts.

I am creating an executable jar files using spring boot application. So when I package the application using maven, all those files go inside jar files as expected.Now, In a function inside code , I have a command as follow

 Process p = Runtime.getRuntime().exec(run generator/generate.py)

generate.py is basically a python file containing stuffs to do.When I run the application within intellij , it works fine . When I package it and try to execute the jar file , it is not able to find the file and complaining .

Error running generator/generate.py: Cannot run program "generator/generate.py" (in directory "file:/Users/bpokharel/code/oprime_fm_service/target/oprime-fmservice-V1.jar!/BOOT-INF/classes!/scripts"): error=2, No such file or directory

failed to parse or execute scripts/commands.txt:45 [run generator/generate.py]

My resource folder is as follow:-

resources/scripts/commands.txt
resources/scripts/generator/generate.py

commands.txt contains other commands. One of the command is generator/generate.py. So I am basically reading commands.txt and executing each scripts as defined in commands.txt

I am reading commands.txt using inputstream and then executing each commands. I believe Runtime.getRunTime tries to execute the command in a directory. , but for executable jar file I am not sure how I can supply folder name where to execute the command

Any help would be appreciated . Here is somewhat related but I have to go one step further than this .

Classpath resource not found when running as jar

Community
  • 1
  • 1
Bishu
  • 31
  • 1
  • 4
  • Check http://stackoverflow.com/questions/12875115/java-execute-shell-script-bundled-within-jar . This discussion has similar context. Hope this helps. – Noman Khan Oct 13 '16 at 18:44
  • Thanks . Will try copying to temp directory and executing command from there. – Bishu Oct 14 '16 at 13:43

0 Answers0