maven打包,使用shade插件,避免出現加載spring配置文件報錯的問題

pom文件內容:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>com.lanxin.eacq.batch.AppForExport</mainClass> <!--主類-->
                            </transformer>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

使用shade的好處:
	之前使用assembly插件打包的時候,執行jar包時會報錯,意思就是找不到spring的xsd文件,spring在啓動時會加載xsd文件,
它首先會到本地查找xsd文件(一般都會包含在spring的jar包中),如果找不到則會到xml頭部定義的url指定路徑下中去尋找xsd,如果找不到則會報錯。
而使用assembly插件打包的時候,它有時候會漏掉這些xsd文件,導致報錯。
	使用shade打包時,可以通過上面的配置意思是把spring.handlers和spring.schemas文件以append方式加入到構建的jar包中,
這樣就不會出現xsd找不到的情況。

有兩篇寫的關於這個的問題,寫的超級好,如果你本地執行jar包,遇到加載xml文件報錯,出現這個異常
org.xml.sax.SAXParseException'http://www.springframework.org/schema/beans/spring-beans-3.1.xsd', because 1) could not find the document; 2) the document could not be read; 3) 看了他們的就會明白了。

http://blog.csdn.net/u013385925/article/details/77678370

http://blog.csdn.net/bluishglc/article/details/7596118



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章