如何使用rpm-maven-plugin在linux上运行我的应用程序?

时间:2016-08-09 09:07:20

标签: maven rpm rpmbuild rpm-spec rpm-maven-plugin

我想使用rpm-maven-plugin将我的maven项目打包到rpm文件。在maven安装(mvn clean install)之后,rpm将在target/rpm/rpm-build/RPMS/noarch/中创建。 我该如何启动应用程序? 如果我尝试使用yum localinstall {name}.rpm安装rpm,我会得到一个提示:没有任何东西是todo: german error text

我在安装后创建了一个文本文件来理解例程。

在我看来,生成的spec文件看起来很奇怪,因为tmp-buildroot /是空的:

%define __jar_repack 0
Name: rpm-build
Version: 0.5.0
Release: SNAPSHOT20160809082044
Summary: rpm-build
License: (c) 2016 Nobody
Vendor: Nobody
URL: http://www.Nobody.com
Group: Development
Packager: Nobody
autoprov: yes
autoreq: yes
BuildArch: noarch
BuildRoot: /mnt/hgfs/workspace/test/rpm-build/target/rpm/rpm-build/buildroot

%description
test example: RPM Package.

%install

if [ -d $RPM_BUILD_ROOT ];
then
  mv /mnt/hgfs/workspace/test/rpm-build/target/rpm/rpm-build/tmp-buildroot/* $RPM_BUILD_ROOT
else
  mv /mnt/hgfs/workspace/test/rpm-build/target/rpm/rpm-build/tmp-buildroot $RPM_BUILD_ROOT
fi

%files

 "/opt/app//lib/"
%config  "/opt/app//conf"
%dir  "/opt/app//logs"

%pre
echo "installing now"

%post
#!/usr/bin/env bash

touch file.txt

我的pom中缺少哪个参数?

<?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">
    <parent>
        <artifactId>nobody</artifactId>
        <groupId>com.nobody.nobody</groupId>
        <version>0.5.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>rpm-build</artifactId>
    <inceptionYear>2016</inceptionYear>
    <organization>
        <name>nobody</name>
        <url>http://www.nobody.com</url>
    </organization>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <app.home>/opt/app/</app.home>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <version>2.1.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>rpm</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <group>Development</group>
                    <description>example: RPM Package.</description>
                    <mappings>
                        <mapping>
                            <directory>${app.home}/lib/</directory>
                            <dependency/>
                            <artifact/>
                        </mapping>
                        <mapping>
                            <directory>${app.home}/conf</directory>
                            <configuration>true</configuration>
                            <sources>
                                <source>
                                    <location>${project.build.outputDirectory}/app.properties</location>
                                    <destination>app.sample.properties</destination>
                                </source>
                            </sources>
                        </mapping>
                        <mapping>
                            <directory>${app.home}/logs</directory>
                        </mapping>
                    </mappings>
                    <preinstallScriptlet>
                        <script>echo "installing now"</script>
                    </preinstallScriptlet>
                    <postinstallScriptlet>
                        <scriptFile>src/main/scripts/postinstall.sh</scriptFile>
                        <fileEncoding>utf-8</fileEncoding>
                    </postinstallScriptlet>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.3</version>
                <configuration>
                    <descriptor>src/assembly/dep.xml</descriptor>
                </configuration>
                <executions>
                    <execution>
                        <id>create-archive</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这是我的项目结构:

project structure

目前正在向我的应用程序发送System.out.println消息。 我的目标是创建一个linux守护进程,我希望可以使用postinstall脚本。

我希望有人对我有所暗示。感谢。

0 个答案:

没有答案