Springboot中的阴影罐

时间:2016-04-15 06:01:00

标签: java maven spring-boot maven-2 maven-plugin

我正在尝试在Spring启动应用程序中构建阴影jar但有一些问题。我不知道我在这里做错了什么。我也阅读了以下链接,但没有运气 maven-shade-plugin error: Cannot find setter, adder nor field in org.apache.maven.plugins.shade.resource.ManifestResourceTransformer for 'resource'

这是我的Pom.xml

<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>dashboard</groupId>
  <artifactId>dashboard</artifactId>
  <packaging>jar</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>

    <dependency>
        <!-- Import dependency management from Spring Boot -->
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>1.2.7.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

  <dependency>
        <groupId>jira.widgets</groupId>
        <artifactId>jira-widgets</artifactId>
        <version>0.1.1-SNAPSHOT</version>
    </dependency> 

         <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    </dependencies> 


    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.1.5.RELEASE</version>
    </parent>



    <!-- Additional lines to be added here... -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <!-- Run shade goal on package phase -->
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <!-- add Main-Class to manifest file -->
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>

                                    <Main-Class>com.text.dashboard.hello.Application</Main-Class>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

    </plugins>
    </build>
</project>

当我运行mvn包时,我在控制台上得到了以下异常

[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building dashboard 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ dashboard ---
[INFO] Deleting C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ dashboard ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ dashboard ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target\classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ dashboard ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ dashboard ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ dashboard ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ dashboard ---
[INFO] Building jar: C:\Users\confiz\Documents\workspace-sts-3.7.3.RELEASE\dashboard\target\dashboard-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.1.5.RELEASE:repackage (default) @ dashboard ---
[INFO] 
[INFO] --- maven-shade-plugin:2.3:shade (default) @ dashboard ---
[WARNING] Map in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer declares value type as: class java.util.jar.Attributes but saw: class java.lang.String at runtime
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.609 s
[INFO] Finished at: 2016-04-15T10:55:02+05:00
[INFO] Final Memory: 22M/224M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.3:shade (default) on project dashboard: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.3:shade for parameter resource: Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer -> [Help 1]
[ERROR] 

场景是:我有两个春季启动项目,两者都有相同类型的可执行jar。我在这个项目中添加了其他项目作为依赖项。这就是为什么我要构建一个具有所有依赖关系的jar

有什么建议吗?

1 个答案:

答案 0 :(得分:6)

我不知道为什么,但它对我有用。只使用

<transformer    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
    <manifestEntries>
        <Main-Class>com.text.dashboard.hello.Application</Main-Class>
    </manifestEntries>
</transformer>

而不是

 <transformers>
     <transformer    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
         <manifestEntries>
             <Main-Class>com.text.dashboard.hello.Application</Main-Class>
         </manifestEntries>
     </transformer>
</transformers>