Rolando Rolando - 1 month ago 16
Java Question

How to execute a script (e.g. mvnw) as if you were in that directory in the background?

I have my application with maven where you can 'cd' to this directory /path/app/execute/. and run 'mvnw' and the app starts fine.

My problem is I want to create a start script in the parent directory here: /path/app/

It's contents are:

nohup /path/app/execute/mvnw &

My problem is, when I cd to /path/app and run './', I am getting:

Error: Could not find or load main class

How can I keep my script in the parent directory of the "mvnw" executable, and be able to execute it as if I were in that directory as a background process (nohup) in the script?

Answer Source

Noting the difference between "mvnw" and "mvn" in your question, if the crux of your problem is changing directory into /path/app/execute under nohup, then:

nohup sh -c 'cd /path/app/execute; mvnw' &