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
1 Answer 1
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}
6 Comments
${@:2} with myflag? There are two places where your parameter may not be passed: service start and jsvc .... Try to determine which of these doesn't work.
$EXEC, for that matter; maybe it's known to all Java programmers? I'm not sure.)