问题
今天遇到个头疼的问题,是zk的配置文件zookeeper.properties被替换了,选择maven,profiles没用。后来发现,打进jar包里的是依赖的jar包的配置文件,被覆盖了。因为提交spark任务的jar包通常是jar-with-dependencies。既需要这个jar又想用自己项目里的properties。
解决方案是:通过assembly.xml文件的方式设置打包需要的jar包内容
pom设置
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
...
assembly.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>
<unpackOptions>
<excludes>
<exclude>core-site.xml</exclude>
<exclude>hdfs-site.xml</exclude>
<exclude>hbase-site.xml</exclude>
<exclude>zookeeper.properties</exclude>
<exclude>*.csv</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>target/classes</directory>
</fileSet>
</fileSets>
</assembly>
总结
之前用azkaban打zip包的时候也用到过这个assemnbly的用xml文件来定义打包的方式。现在发现可能通过unpackOptions来过滤依赖jar包一些文件。记录一下