This commit is contained in:
luoxiang
2019-05-30 23:30:32 +08:00
parent f6a38a059e
commit b2a53fa493
8 changed files with 245 additions and 50 deletions

View File

@ -77,16 +77,40 @@ maven-assembly-plugin是官方文档中介绍的打包方法来源于官方
>
> Then run mvn assembly:assembly to get an appropriately packaged jar. Make sure you [exclude](http://maven.apache.org/plugins/maven-assembly-plugin/examples/single/including-and-excluding-artifacts.html) the Storm jars since the cluster already has Storm on the classpath.
官方文档说明了以下点:
官方文档主要说明了以下点:
- maven-assembly-plugin把所有的依赖一并打到最后的JAR中
- 需要排除掉Storm集群环境中已经提供的Storm jars
- 使用maven-assembly-plugin可以把所有的依赖一并打到最后的JAR中
- 需要排除掉Storm集群环境中已经提供的Storm jars
- 通过` <mainClass>`标签指定主入口类;
- 通过`<descriptorRef>`标签指定打包相关配置。
所以采用maven-assembly-plugin进行打包时配置应该如下:
`jar-with-dependencies`是Maven[预定义](http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies)的一种最基本的打包配置其XML文件如下:
### 1. 基本配置
```xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</assembly>
```
在POM.xml中引入插件并指定打包格式的配置文件`assembly.xml`(名称可自定义)
我们可以通过对该配置文件进行拓展从而实现更多的功能比如排除指定的JAR等。使用示例如下
### 1. 引入插件
在POM.xml中引入插件并指定打包格式的配置文件为`assembly.xml`(名称可自定义)
```xml
<build>
@ -108,7 +132,7 @@ maven-assembly-plugin是官方文档中介绍的打包方法来源于官方
</build>
```
assembly.xml文件内容如下:
`assembly.xml`拓展自`jar-with-dependencies.xml`,使用了`<excludes>`标签排除Storm jars具体内容如下:
```xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
@ -232,7 +256,7 @@ assembly.xml文件内容如下
</plugin>
```
以上配置示例来源于StormGithub上的examples,这里做一下说明:
以上配置示例来源于Storm Github这里做一下说明
在上面的配置中排除了部分文件这是因为有些JAR包生成时会使用jarsigner生成文件签名完成性校验分为两个文件存放在META-INF目录下