How to use run-time environment variables with rpm-maven-plugin

427 Views Asked by At

I am generating an RPM using rpm-maven-plugin. I would like to specify the destination directory using the relevant run-time env variable. The problem is that the plugin evaluates the variable during compile time.

For example the ${JAVA_HOME}:

<mapping>
    <directory>${JAVA_HOME}/ext</directory>
    <sources>
        <source>
            <location>/home/user/run.sh</location>
        </source>
    </sources>
</mapping>

I want the directory in the RPM spec file to stay ${JAVA_HOME}/ext and only to be evaluated during RPM installation, i.e. run-time.

1

There are 1 best solutions below

1
zforgo On

Accordind to this documentation each environment variable is available with env. prefix. So you can use it like this:

<mapping>
    <directory>${env.JAVA_HOME}/ext</directory>
    <sources>
        <source>
            <location>/home/user/run.sh</location>
        </source>
    </sources>
</mapping>

Note

There are two different properties which is different.

  • ${env.JAVA_HOME} is an environment variable and it's may not be set.
  • ${java.home} is a predefined System Property which points to the Java installation folder.