Storm的topology项目打包部署时"multiple defaults.yaml resources"错误

 

最近在做日志实时分析,用的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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值