I have a java program that runs as a service in linux box. I have shell script file that has the following line to start the program.
$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS
$CLASS_PATH has class path
$CLASS has the name of main class
EXEC="/usr/bin/jsvc"
I can start and stop the service using following commands
service myscriptfilename start
service myscriptfilename stop
Now I added a new argument to my program called "myflag" . It works fine on windows box . Now I am having difficulty passing the new argument to my program on my linux box using the shell script.
Now I am starting my service as
service myscriptfilename start myflag
I can get the value of myflag using $2 in shell script. I am trying to figure out how do I pass that to my program
How can i pass my "myflag" to my program from shell script in the following line?
$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS
I am considering that $EXEC
is java executable, $1
is your JAR, $CLASS
is your main class. In this case just append ${@:2}
to the end of the line:
$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS ${@:2}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.