我是靠谱客的博主 纯真康乃馨,最近开发中收集的这篇文章主要介绍用maven把所有类文件打到一个jar里面,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

为什么80%的码农都做不了架构师?>>>   hot3.png

storm是提交jar包运行程序的,这就需要解决依赖包的问题通常有两种办法 :1.把依赖包放到storm的classpath下,2,把依赖包和自己的程序打成一个整包。

maven有assembly插件支持第二种,看pom.xml

    <dependencies>
        <dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-core</artifactId>
            <version>0.9.5</version>
            <scope>provided</scope>
        </dependency>
        
        <!--
        自己程序依赖的包
        -->
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.xxx.storm.NotifyTopology</mainClass>
                        </manifest>
                    </archive>
                    <descriptors>
                        <descriptor>src/main/assembly/src.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

 

再看src/main/assembly/src.xml

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>without_storm</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <useProjectArtifact>true</useProjectArtifact>
            <outputDirectory>/</outputDirectory>
            <unpack>true</unpack><!--解压-->
            <scope>runtime</scope>
            <excludes>
                <exclude>xxx-storm*:jar</exclude><!--自身的包-->
            </excludes>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <directory>${project.basedir}targetclasses</directory>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

 

上面dependencySet排除自身的包,因为target/classes中已经有对应的class了,

排除storm本身的包在storm的dependency中加<scope>provided</scope>

转载于:https://my.oschina.net/yu120/blog/683547

最后

以上就是纯真康乃馨为你收集整理的用maven把所有类文件打到一个jar里面的全部内容,希望文章能够帮你解决用maven把所有类文件打到一个jar里面所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部