最近在做日志实时分析,用的Storm做.topology代码已经写好,用的maven项目.
用了"mvn assembly:assembly"命令,包括所依赖的jar包一起打包.
但将jar包提交到服务器上部署时报错:
java.io.IOException: Found multiple defaults.yaml resources. You're probably bundling the Storm jars with your topology jar. [jar:file:/usr/local/jstorm-1.1.2/jstorm-core-1.1.2.jar!/defaults.yaml,jar:file:/usr/local/jstorm-1.1.2/wait_deploy/test-jstorm-bolt.jar!/defaults.yaml
究其原因是maven项目中有:
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>1.1.2</version>
</dependency>
与服务器中的storm-core包中的defaults.yaml文件冲突
查看网上解决方案,又说在<dependency>中加<scope>provided</scope>,但楼主加上之后打出来的jar包里面依然带defaults.yaml.
然后去Stack OverFlow上找到解决方案(原帖地址:https://stackoverflow.com/questions/31942316/how-to-exclude-certain-jar-dependencies-while-creating-jar-without-using-maven):
将pom.xml中的plugin替换为:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>/src/main/resources/exclude-storm.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>path.to.main.class</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
同时根据上面的
<descriptors>
<descriptor>/src/main/resources/exclude-storm.xml</descriptor>
</descriptors>
创建一个xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<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>exclude-storm</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<unpack>true</unpack>
<scope>compile</scope> <!-- note here!!!! -->
<excludes>
<exclude>org.apache.storm:storm-core:jar:1.1.1</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>
然后用"mvn clean assemly:assembly"打包.
打包后的jar包不包括default.yaml