• maven-assembly-plugin 插件打包一个bug手动解决方式


    dubbo采用Main独立运行后,我采用maven打包又遇到新的打包

    我的maven-build配置为

      <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <compilerVersion>${java-version}</compilerVersion>
                        <source>${java-version}</source>
                        <target>${java-version}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
    
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <includes>
                            <include>**/*Tests.java</include>
                        </includes>
                    </configuration>
                </plugin>
    
                 <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.xxxxx.cardbag.service.AppMain</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <!--第二种shade打包最后运行的时候会出现mybatis xml文件错误,而用assembly插件手动加spring映射文件后就不会出现错误-->
                <!--以下解决了spring.schemas 等文件的映射问题,但又会出现新的mybatis xml配置问题-->
                <!--<plugin>-->
                    <!--<groupId>org.apache.maven.plugins</groupId>-->
                    <!--<artifactId>maven-shade-plugin</artifactId>-->
                    <!--<version>2.4.3</version>-->
                    <!--<executions>-->
                        <!--<execution>-->
                            <!--<phase>package</phase>-->
                            <!--<goals>-->
                                <!--<goal>shade</goal>-->
                            <!--</goals>-->
                            <!--<configuration>-->
                                <!--<filters>-->
                                    <!--<filter>-->
                                        <!--<artifact>*:*</artifact>-->
                                        <!--<excludes>-->
                                            <!--<exclude>META-INF/*.SF</exclude>-->
                                            <!--<exclude>META-INF/*.DSA</exclude>-->
                                            <!--<exclude>META-INF/*.RSA</exclude>-->
                                        <!--</excludes>-->
                                    <!--</filter>-->
                                <!--</filters>-->
                                <!--<transformers>-->
                                      <!--<transformer-->
                                            <!--implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">-->
                                        <!--<mainClass>com.xxxxx.cardbag.service.AppMain</mainClass>-->
                                    <!--</transformer>-->
                                    <!--<transformer-->
                                            <!--implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">-->
                                        <!--<resource>META-INF/spring.handlers</resource>-->
                                    <!--</transformer>-->
                                    <!--<transformer-->
                                            <!--implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">-->
                                        <!--<resource>META-INF/spring.schemas</resource>-->
                                    <!--</transformer>-->
                                <!--</transformers>-->
                            <!--</configuration>-->
                        <!--</execution>-->
                    <!--</executions>-->
                <!--</plugin>-->
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <archive>
                            <addMavenDescriptor>false</addMavenDescriptor>
                            <manifest>
                                <!-- 是否要把第三方jar放到manifest的classpath中 -->
                                <addClasspath>true</addClasspath>
                                <!--生成的manifest中classpath的前缀,因为要把第三方jar放到lib目录下,所以classpath的前缀是lib/-->
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.xxxxxx.cardbag.service.AppMain</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.0.0</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <includeTypes>jar</includeTypes>
                        <overWriteSnapshots>true</overWriteSnapshots>
                        <type>jar</type>
                        <outputDirectory>${project.build.directory}/lib</outputDirectory>
    
                        <!--<outputDirectory>${project.build.directory}/lib</outputDirectory>-->
                        <!--<overWriteReleases>false</overWriteReleases>-->
                        <!--<overWriteSnapshots>false</overWriteSnapshots>-->
                        <!--<overWriteIfNewer>true</overWriteIfNewer>-->
                        <!--<includeScope>compile</includeScope>-->
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
    
            </plugins>
        </build>

    maven-assembly-plugin 插件打包成功后运行会包,错误信息如下:
    Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]

    出现这个错误的原因主要是 它在对第三方打包时,对于 META-INF 下的 spring.handlers,spring.schemas 等多个同名文件进行了覆盖,遗漏掉了一些版本的 xsd 本地映射。

    这里在打包好后,我们手动从spring-jdbc jar包里把 spring.handlers,spring.schemas spring.tooling解压出来,再放进去我们生成的jar包里面,最后 执行  java -jar xxx.jar   运行成功

  • 相关阅读:
    int 和 Integer 有什么区别
    Exception、Error、运行时异常与一般异常有何异同
    Redis存储系统
    MySpring-06.基于XML的IOC的案例
    Spring MVC技术之【上机】
    MySpring-05.基于XML的IOC的案例1
    MySpring-04.Spring的常用注解
    MySpring-03.Spring的 IOC 和 DI
    MySpring-02.程序间耦合
    Spring框架之【上机】
  • 原文地址:https://www.cnblogs.com/fangyuan303687320/p/7802693.html
Copyright © 2020-2023  润新知