我正在尝试使用rpm maven插件构建一个rpm安装。此外,我还试图编辑我的安装后脚本,以便使用一些Maven属性。因此,我使用maven资源插件。
我在关注这篇文章中的答案,但它对我来说不起作用,文件也没有被过滤并保存在目标目录中。
我的项目结构:
-my-app
-pom.xml
-app module
-src/..
-pom.xml
-rpm module
-pom.xml
-src/main/
-resources
-scripts
-post-install.sh
在rpm模块pom.xml中,我有以下两个插件:
<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>
以及:
<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>
当我运行mvn包时,我得到以下错误:
[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]
我还尝试将include标记的值更改为**/post-install.sh
,但没有成功。
要用maven在另一个文件中设置的值替换文件中的值,这是一个好方法:
<!-- 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>
此配置将从属性文件中设置的值替换文件中的值。如果只想将要更新的值或变量设置为pom.xml中的属性,可以只使用pom.xml的<properties> <yourVar>someValue</yourVar> </properties>
选项,而不是
<filters>
<!-- the file where the variable values will be updated -->
<filter>file.properties</filter>
</filters>