3

我试图从 Spring Boot 运行 Hello World 示例。当我在模块上运行“mvn package”时,出现以下错误:-

[错误] 无法在项目 spring.boot 上执行目标 org.apache.maven.plugins:maven-shade-plugin:2.1:shade (default): Unable to parse configuration of mojo org.apache.maven.plugins:maven->阴影->插件:2.1:参数转换器的阴影:在 org.apache.maven.plugins.shade.resource.ManifestResourceTransformer 中找不到“资源”的设置器、加法器或字段 -> [帮助 1]

我没有使用任何“资源”属性,但似乎对此有所抱怨。知道我在这里做错了什么

这是模块的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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework</groupId>
    <artifactId>spring.boot</artifactId>
    <version>0.1.0</version>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.0.1.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>hello.SampleController</Main-Class>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
4

2 回答 2

6

您可以尝试的第一件事是不使用 shade 插件(这通常是 spring-boot 插件的劣质解决方案)。spring-boot 插件应该是您在 spring.io 的所有示例和指南中找到的插件。使用 starter-parent 非常简单:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

父母已经有一个配置ManifestResourceTransformer,所以我认为这就是问题所在。如果您删除<executions/>并设置一个属性start-class,它应该可以工作。

如果你出于某种原因需要使用 shade 并且你想控制配置,那么不要使用 starter-parent 作为父级(也许只是将它用于依赖管理)。

于 2014-04-11T05:02:05.030 回答
-1

就我而言,我使用命令提示符 (cmd.exe) 来打包项目。当 maven 打包项目时,它将下载所有插件、依赖项(本例中为Apache Maven Shade Plugin)。cd 到你的项目。类型:

mvn package

打包后就可以使用了。希望能帮助到你。

于 2014-11-26T09:18:11.107 回答