I want to start a java app from git bash in a new window with a process name.
In win cmd it is simple start "appname" java -jar /path/to.jar
for example.
But in git bash I get an error The system cannot find the file javaapp
Sidenotes
- windows 10 environment
- I use git bash as my primary terminal because of the unix commands available there and because of the git repository status visible inside the prompt.
- The main reason for naming the process is that I have a shell script that starts multiple java apps, and a shell script to kill them all. For the kill part I need the PID of that process
- I followed this great tutorial on springhow.com but in that the process is not started in the new window and if I try to use
start
it gives the wrong pid (not the pid of the java app) so I tried the solution in this stackoverflow answer but it does not work in bash
If it helps, this is the script (mainly inspired from the link above) to start instances:
#!/bin/bash
#------ DECLARATIONS
app_path=./target/1.0-SNAPSHOT.jar
pidFile=./pid.file
instances=1
#------ BUILD IF NEEDED
if [ ! -f $app_path ];
then
echo Building project...
mvn clean package
else
echo Using existing project build
fi
#------ UPDATING INSTANCES COUNT FROM PARAM IF PRESENT
if [ ! -z "$1" ]; then
instances=$1
fi
echo Starting "$instances" "$app_path" instances
#------ CLEARING PID FILE
> $pidFile
#------ STARTING INSTANCES
for (( i = 0; i < instances; i++ )); do
start java -jar $app_path &
echo $! >> $pidFile
done
echo NOTES:
echo " " Process ids for "$app_path" instances stored in "$pidFile"
echo " " To stop instances type Ctrl+C on each or run stop_multi_apps.sh script that will stop processes with ids from "$pidFile"