Maven Appassembler plugin - redirecting stdout and / or stderr

I am migrating one Java project to Maven and we are using the Appassembler maven plugin (version 1.3) to create a shell start script. My problem is how to redirect stdout and / or java program output? Appassembler pom.xml configuration

        <program>
          <mainClass>com.mycompany.app.App</mainClass>
          <commandLineArguments>
            <commandLineArgument>arg1</commandLineArgument>
            <commandLineArgument>arg2</commandLineArgument>
          </commandLineArguments>
          <name>app</name>
        </program>

      

generates:

exec "$JAVACMD" $JAVA_OPTS \
  $EXTRA_JVM_ARGUMENTS \
  -classpath "$CLASSPATH" \
  -Dapp.name="app" \
  -Dapp.pid="$$" \
  -Dapp.repo="$REPO" \
  -Dbasedir="$BASEDIR" \
  com.mycompany.app.App \
  arg1 arg2 "$@"

      

The placeholder ($ @) parameters are the last generated token at the beginning of the script.

+3


source to share


1 answer


Found a workaround for this issue. Fortunately, the placeholder parameter is on the same line as the command line arguments. So this pom.xml config:

<commandLineArguments>
    <commandLineArgument>"$@"</commandLineArgument>
    <commandLineArgument>&gt;&gt;out.log</commandLineArgument>
    <commandLineArgument>2&gt;&amp;1</commandLineArgument>
    <commandLineArgument>#</commandLineArgument>
</commandLineArguments>

      

will generate script:



....
com.mycompany.app.App \
"$@" >>out.log 2>&1 # "$@"

      

The hash is a comment in bash, so the last parameter placeholder will be ignored and this hack will do the redirection job.

+3


source







All Articles