`
sunxboy
  • 浏览: 2871207 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Maven打包实践: include all dependency jars

 
阅读更多

有时我们需要将应用打包, 并将所有依赖的包全部打一入大的jar包中.

有很多工具可以这样做, 另外当我们的应用中有使用spring时, 在spring的配置文件中一般会声明一下Spring Schema,在使用其它打包工具将所有依赖包打入一个大包中在运行时,会报 "Can't Find Beans Schema" 的错误, 下面的这种做法可以避免这样的问题出现:

使用maven shade plugin:

<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-shade-plugin</artifactId>
			<version>1.3.1</version>
			<executions>
			    <execution>
			        <phase>package</phase>
			        <goals>
			            <goal>shade</goal>
			        </goals>
			        <configuration>
			            <finalName>${project.artifactId}-${project.version}-final</finalName>
			            <shadedArtifactAttached>true</shadedArtifactAttached>
			            <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
			            <transformers>
			                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
			                    <mainClass>com.eifesun.platform.application.ApplicationLauncher</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>
				          <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
				            <resource>META-INF/spring.tooling</resource>
				          </transformer>
			            </transformers>
			        </configuration>
			    </execution>
			</executions>
			</plugin>

 特别要注意:

META-INF/spring.handlers

META-INF/spring.schemas

META-INF/spring.tooling

不要遗漏了,不然就会报"Can't Find Beans Schema"的错误.

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics