2

I'm trying to build an rpm install with rpm-maven-plugin. In addition, I'm also trying to edit my post install script in order to use some Maven properties. For that reason, I'm using maven-resources plugin.

I'm following the answers in this post but it just doesn't work for me and the files aren't filtered and saved in the target directory.

My projects structure :

-my-app
   -pom.xml
   -app module
       -src/..
       -pom.xml
   -rpm module
       -pom.xml
       -src/main/
           -resources
           -scripts
               -post-install.sh

In the rpm module pom.xml I have the following two plugins :

<build>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <resources>
                        <resource>
                            <directory>src/main/scripts/</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>post-install.sh</include>
                            </includes>
                        </resource>
                </configuration>
            </plugin>

and also :

   <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                  .......
                <postinstallScriptlet>
                        <scriptFile>${basedir}/target/classes/post-install.sh</scriptFile>
                        <fileEncoding>utf-8</fileEncoding>
                </postinstallScriptlet>

When I run mvn package I'm getting the following error :

[ERROR] Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.2.0:rpm (default-rpm) on project my-app-package: Execution default-rpm of goal org.codehaus.mojo:rpm-maven-plugin:2.2.0:rpm failed: Invalid scriptlet declaration found - defined scriptFile does not exist: /root/my-app/rpm/target/classes/post-install.sh -> [Help 1]

I also tried to change the value of the include tag to **/post-install.sh but it didn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
JeyJ
  • 3,582
  • 4
  • 35
  • 83
  • Why would you like to filter a post-install.sh related to RPM ? RPM has a post-install script which is not ".sh" !!! – khmarbaise Apr 13 '21 at 17:43
  • I want to use one of the maven properties inside the post-install script – JeyJ Apr 13 '21 at 17:45
  • Can you be more specific what you like to do exactly? – khmarbaise Apr 13 '21 at 17:53
  • I would like to replace the maven properties that I use in the post-install with their value.. As you can see in the post that suggested the answer to this orig problem – JeyJ Apr 13 '21 at 21:09

1 Answers1

0

To replace values in a file with values set in another file with maven this is a good way:

<!-- path to the final location of the resulting modified file - your output -->
<properties>
    <filesPath>/Users/.../config/files</filesPath>
</properties>


<build>
    <resources>
        <resource>
        <!-- the file to be modified. Here the name of the values to be changed in the properties file need to be added as variable names, e.g. ${varName} -->
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <!-- the file name or file types to be edited/updated -->
                <include>*.xml</include>
            </includes>
            <!-- the target path is the location where the generated/edited resulting files should be saved. The default is `target/classes/` -->
            <targetPath>${jdbcConfigFilesPath}</targetPath>
        </resource>
    </resources>

    <filters>
        <!-- the file where the variable values will be updated -->
        <filter>file.properties</filter>
    </filters>

</build>

This configuration will replace values in files from values set in a properties file. If one wants to just set the values or the variables to be updated as properties in the pom.xml, one can just use the <properties> <yourVar>someValue</yourVar> </properties>option in the pom.xml instead of the

<filters>
    <!-- the file where the variable values will be updated -->
    <filter>file.properties</filter>
</filters>
Petronella
  • 2,327
  • 1
  • 15
  • 24