maven插件中fatjar的可选jar包含

r1zhe5dt  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(344)

如何创建具有特定依赖项的胖jar。我有Spark项目,需要2个外部jar,我想添加到应用程序jar。当我创建可执行jar时,jar中不包含依赖项,当我创建fatjar时,所有依赖项都被添加,包括spark等。。我只想把那两个jar放进我的jar里。下面是我使用maven汇编插件创建的pom文件。

<dependencies>

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.11</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-sql_2.11</artifactId>
        <version>2.2.0</version>
    </dependency>

    <!-- Below dependencies need to be added in Application jar -->

    <dependency>
        <groupId>netacuity</groupId>
        <artifactId>common-netacuity-db</artifactId>
        <version>3.1.2</version>
    </dependency>
    <dependency>
        <groupId>netacuity</groupId>
        <artifactId>common</artifactId>
        <version>2.1.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <!-- get all project dependencies -->
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <!-- MainClass in mainfest make a executable jar -->
                <archive>
                    <manifest>
                        <mainClass>com....App</mainClass>
                    </manifest>
                </archive>

            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <!-- bind to the packaging phase -->
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
ff29svar

ff29svar1#

你可以用 scope 为了这个。默认情况下 scopecompile 所以当你打包的时候,所有的jar都会包括在内。
要包含一个jar,您可以 scope 作为 compile 并保持 default ```

netacuity
common-netacuity-db
3.1.2
compile

要排除jar,可以更改 `scope` 至 `provided` . 这些jar应该在运行时可用。

相关问题