2

我是 Maven 和 RPM 生产的新手。

我已经能够成功地构建一个 WAR,将它打包到一个 RPM 中并安装它。

要构建 rpm,我使用以下命令:

mvn install rpm:rpm

这将构建 WAR 文件,将其安装到我的本地存储库并生成 RPM 文件。

我的问题是:

我配置 rpm-maven-plugin 的方式是否违反了规范或标准?

我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>myGroupId</groupId>
    <artifactId>myapp</artifactId>
    <version>1.1.0</version>
    <packaging>war</packaging>
    <name>My App</name>

    ...

    <build>
        <sourceDirectory>${basedir}/src</sourceDirectory>
        <scriptSourceDirectory>${basedir}/src/main/scripts</scriptSourceDirectory>
        <testSourceDirectory>${basedir}/src/test/java</testSourceDirectory>
        <outputDirectory>${basedir}/target/classes</outputDirectory>
        <testOutputDirectory>${basedir}/target/test-classes</testOutputDirectory>
        <resources>
            <resource>
                <directory>${basedir}/src</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>${basedir}/src/test/resources</directory>
            </testResource>
        </testResources>
        <directory>${basedir}/target</directory>
        <finalName>myapp</finalName>
        <pluginManagement>
        <plugins>
            ...
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <version>2.1.5</version>
                <configuration>

                    <defineStatements>
                        <defineStatement>_project myproject</defineStatement>
                        <defineStatement>_tomcat_root ${TOMCAT_ROOT}</defineStatement>
                    </defineStatements>

                    <copyright>myCopyright</copyright>
                    <distribution>myApp</distribution>
                    <group>Applications/System</group>
                    <description>
                        My description
                    </description>

                    <defaultDirmode>755</defaultDirmode>
                    <defaultFilemode>644</defaultFilemode>
                    <defaultGroupname>myapp</defaultGroupname>
                    <defaultUsername>myapp</defaultUsername>
                    <mappings>
                        <mapping>
                            <directory>%{_tomcat_root}/webapps</directory>
                            <configuration>true</configuration>
                            <sources>
                                <source>
                                    <location>../MyApp/config</location>
                                </source>
                            </sources>
                        </mapping>
                        <mapping>
                            <directory>%{_tomcat_root}/webapps</directory>
                            <artifact>
                                <classifiers>
                                    <classifier/>
                                </classifiers>
                            </artifact>
                        </mapping>
                    </mappings>

                    <preinstallScriptlet>
                        <script>
                            echo "Installing to Tomcat Root Directory: %{_tomcat_root}"
                            echo "stopping tomcat6"
                            /etc/init.d/tomcat6 stop
                        </script>
                    </preinstallScriptlet>
                    <postinstallScriptlet>
                        <script>
                            echo "Running postinstallScriptlet - script"
                            echo "starting tomcat6"
                            /etc/init.d/tomcat6 start
                        </script>
                    </postinstallScriptlet>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
4

0 回答 0