Java 使用 maven 的 RPM 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20230324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:26:51  来源:igfitidea点击:

RPM package using maven

javamavenunixrpmrpm-maven-plugin

提问by anton91

I am trying to build an RPM package using the maven plugin.

我正在尝试使用 maven 插件构建 RPM 包。

If I add the plugin configuration the RPM package is not made, the manual on the RPM plugin site says the package tag should be RPM however this seems to cause the build to fail saying that this destination is it valid.

如果我添加插件配置 RPM 包没有被制作,RPM 插件站点上的手册说包标签应该是 RPM 但这似乎导致构建失败,说这个目标是有效的。

Does anyone have any examples they could share?

有没有人有任何可以分享的例子?

EDITThe error is Unknown packaging: rpm

编辑错误是未知包装:rpm

<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>rpm</packaging>

<profile>
            <id>local</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/properties/dev</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources/txt</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources/universal</directory>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>rpm-maven-plugin</artifactId>
                        <version>2.1-alpha-3</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>generate-rpm</id>
                                <goals><goal>rpm</goal></goals>
                                <phase>prepare-package</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <summary>...</summary>
                            <name>...</name>
                            <version>...</version>
                            <release>...</release>
                            <vendor>...</vendor>
                            <packager>...</packager>
                            <group>Application</group>
                            <mappings>
                                <mapping>
                                    <directory>/tmp/testing</directory>
                                </mapping>
                            </mappings>
                            <!--<requires>filesystem, bash, grep</requires>-->

                            <description>
                                ...
                            </description>

                            <prepareScript>RPMScripts/prep.bash</prepareScript>
                            <preinstallScript>RPMScripts/preInstall.bash</preinstallScript>
                            <install>RPMScripts/install.bash</install>
                            <postinstall>RPMScripts/postInstall.bash</postinstall>
                            <cleanScript>RPMScripts/clean.bash</cleanScript>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <failOnError>true</failOnError>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                    <plugin> 
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.8</version>
                        <executions>
                            <execution>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.16</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>

采纳答案by blong

The error is referencing the line :

错误引用了该行:

<packaging>rpm</packaging>

At issue is the fact that your packaging is actually a plugin construct, not a built-in maven package type. Omitting the line will resolve the error.

问题在于您的打包实际上是一个插件构造,而不是内置的 maven 包类型。省略该行将解决错误。

回答by Fenn

The only answers to this question basically say "if packaging of rpm is giving errors, just don't use it". I am running into the exact same thing, so I will try to shed some more light on the issue.

这个问题的唯一答案基本上是说“如果 rpm 的包装出现错误,请不要使用它”。我遇到了完全相同的事情,所以我将尝试更多地了解这个问题。

Someone once said "maven doesn't suck, but maven documentation does"

有人曾经说过“maven 不烂,但 Maven 文档很烂”

Here is what I have found -

这是我发现的 -

First... the default packaging types aren't the only packaging types you can use in maven, as stated here:

首先......默认包装类型不是您可以在 maven 中使用的唯一包装类型,如下所述:

http://books.sonatype.com/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html

http://books.sonatype.com/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html

To define a new lifecycle for a new packaging type, youbll need to configure a LifecycleMapping component in Plexus. In your plugin project, create a META-INF/plexus/components.xml under src/main/resources. In components.xml add the content from Overriding the Default Lifecycle. Set the name of the packaging type under role-hint, and the set of phases containing the coordinates of the goals to bind (omit the version). Multiple goals can be associated with a phase using a comma delimited list.

要为新的包装类型定义新的生命周期,您需要在 Plexus 中配置 LifecycleMapping 组件。在您的插件项目中,在 src/main/resources 下创建一个 META-INF/plexus/components.xml。在 components.xml 中添加来自 Overriding the Default Lifecycle 的内容。在角色提示下设置打包类型的名称,以及包含要绑定的目标坐标的阶段集(省略版本)。可以使用逗号分隔列表将多个目标与一个阶段相关联。

Using this as a starting point I searched for "plexus" and discovered that is a IoC (Inversion of Control) Component Framework. A bit like Spring (read Martin Fowler's IoC Article) it helps with "dependency injection" which is to say it makes java more flexible about runtime jar and class file identification and loading, especially if such details as the name of the classes are to be configured at runtime in XML files (for example). Which is something Python and Ruby don't really have to worry about because they are not so concerned with knowing everything at compile time as Java is. The plexus/components.xml is just such a file. Also it helps to know that a Maven Plugin is a plexus component - that is, it is a dependency to be injected - in this case that dependency is a jar, which is a zip file full of class files - a class file describes a "java object" or a "plain old java object" also called a POJO. A POJO for use by Maven is a MOJO - so all Maven plug-ins are MOJOs - and the thing which handles plugging in of the plug-in for Maven is Plexus (at least in Maven 2). So lets hunt through the plug-in source code to see if they have a components.xml file with a "role-hint" of rpm.

以此为起点,我搜索了“plexus”并发现它是一个 IoC(控制反转)组件框架。有点像 Spring(阅读 Martin Fowler 的 IoC 文章)它有助于“依赖注入”,也就是说它使 Java 在运行时 jar 和类文件识别和加载方面更加灵活,特别是如果类的名称等细节要在运行时在 XML 文件中配置(例如)。这是 Python 和 Ruby 真正不必担心的事情,因为它们不像 Java 那样关心在编译时了解所有内容。plexus/components.xml 就是这样一个文件。此外,了解 Maven 插件是一个 plexus 组件也有帮助 - 也就是说,它是一个要注入的依赖项 - 在这种情况下,该依赖项是一个 jar,这是一个充满类文件的 zip 文件 - 类文件描述了“java 对象”或“普通的旧 java 对象”,也称为 POJO。供 Maven 使用的 POJO 是 MOJO - 所以所有 Maven 插件都是 MOJO - 并且处理 Maven 插件的插件是 Plexus(至少在 Maven 2 中)。因此,让我们搜索插件源代码,看看它们是否有一个带有 rpm “角色提示”的 components.xml 文件。

...and they do... ("use the source, Luke")

......他们确实......(“使用来源,卢克”)

we can also use gihub's GIT Blame feature to see who documented what when the "role-hint" was added and what other files were changed at the same time.

我们还可以使用 gihub 的 GIT Blame 功能来查看谁记录了添加“角色提示”时的内容以及同时更改了哪些其他文件。

github.com - rpm-maven-plugin - blame - 0efd27d3beb64c291b960731fe1bdbbb5dbd938e - src/main/resources/META-INF/plexus/components.xml

github.com - rpm-maven-plugin - 责备 - 0efd27d3beb64c291b960731fe1bdbbb5dbd938e - src/main/resources/META-INF/plexus/components.xml

[MOJO-1249] Create rpm as primary artifact

[MOJO-1249] 创建 rpm 作为主要工件

Submitted By: Brett Okken Carlos Sanchez committed on Jan 2, 2009

提交人:Brett Okken Carlos Sanchez 于 2009 年 1 月 2 日提交

github.com - rpm-maven-plugin - commit - fb9bc1ae7488dc0fa6853cdd874fc907c628122d

github.com - rpm-maven-plugin - 提交 - fb9bc1ae7488dc0fa6853cdd874fc907c628122d

3 files where changes at the same time:

3 个同时更改的文件:

src/main/java/org/codehaus/mojo/rpm/RPMMojo.java

src/main/java/org/codehaus/mojo/rpm/RPMMojo.java

src/main/resources/META-INF/plexus/components.xml

src/main/resources/META-INF/plexus/components.xml

src/site/apt/usage.apt

src/site/apt/usage.apt

The usage.apt file is the documentation and these sections were added

usage.apt 文件是文档,并添加了这些部分

+
+ The packaging value should be set to "<<<rpm>>>".
++-------+
+<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/maven-v4_0_0.xsd ">
+ <modelVersion>4.0.0</modelVersion>
+ ...
+ <packaging>rpm</packaging>
+ ...
+</project>
++-------+
+
+ The extensions tag for this plugin should be marked true.
+
++-------+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>rpm-maven-plugin</artifactId>
+ <extensions>true</extensions>
+ ...
+ </plugin>
+ </plugins>
+ </build>
++-------+

The whole documentation file is:

整个文档文件是:

github.com - rpm-maven-plugin - usage.apt

github.com - rpm-maven-plugin - usage.apt

Since I was curious I looked up "apt markup" -

由于我很好奇,我查了一下“apt markup”——

www.beaglebytes.com - creating-a-document-using-apt-v01.html

www.beaglebytes.com - created-a-document-using-apt-v01.html

Almost Plain Text (APT) is a very simple yet powerful markup language. It is particularly interesting because it enables you to create neatly formatted HTML, RTF, and other output formats from a document that appears to be in plain text. As the documentation says:

几乎纯文本 (APT) 是一种非常简单但功能强大的标记语言。它特别有趣,因为它使您能够从看似纯文本的文档中创建格式整齐的 HTML、RTF 和其他输出格式。正如文档所说:

APTconvert is a command-line tool that can be used to convert the APT format to HTML, XHTML, PDF, PostScript, (MS Word loadable) RTF, DocBook SGML and DocBook XML.

APTconvert 是一个命令行工具,可用于将 APT 格式转换为 HTML、XHTML、PDF、PostScript、(MS Word 可加载)RTF、DocBook SGML 和 DocBook XML。

The APT format (Almost Plain Text) is a simple markup language (like HTML) than can be used to write simple article-like documents (like HTML). Unlike HTML, APT uses as few markup as possible to express the structure of the document. Instead, APT uses paragraph indentation.

APT 格式(几乎纯文本)是一种简单的标记语言(如 HTML),可用于编写简单的类似文章的文档(如 HTML)。与 HTML 不同,APT 使用尽可能少的标记来表达文档的结构。相反,APT 使用段落缩进。

hope this helps

希望这可以帮助

B r i a n F e n n e l l

布莱恩·芬内尔