簡體   English   中英

包括排除的jar包和Maven Assembly Plugin

[英]Including excluded jar package with Maven Assembly Plugin

有一個pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<!-- other parts -->

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>2.0.0-cdh4.2.1</version>
        <exclusions>
            <exclusion>
                <artifactId>slf4j-log4j12</artifactId>
                <groupId>org.slf4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass></mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
                <execution>
                    <id>index</id>
                    <phase>package</phase>
                    <configuration>
                        <descriptors>
                            <descriptor>src/main/assembly/index.xml</descriptor>
                        </descriptors>
                    </configuration>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>

“ index.xml”程序集文件

<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.1 http://maven.apache.org/xsd/assembly-1.1.1.xsd">
<id>index</id>
<formats>
    <format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<dependencySets>
    <dependencySet>
        <outputDirectory>/</outputDirectory>
        <unpack>false</unpack>
        <includes>
            <include>org.slf4j:slf4j-log4j12</include>
        </includes>
    </dependencySet>
    </dependencySets>

<files>
    <file>
        <source>${project.build.directory}/${artifactId}-${version}-jar-with-dependencies.jar</source>
        <fileMode>0644</fileMode>
        <outputDirectory>/</outputDirectory>
        <destName>${artifactId}-${version}-index.jar</destName>
    </file>
</files>
</assembly>

使用maven預定義程序集描述符“ jar-with-dependencies”生成的jar將在Storm中使用,必須排除slf4j-log4j12軟件包,Storm也包括它。 但是其中有一個“ indexer”類是獨立使用的,它需要slf4j-log4j12包進行記錄,在運行“ maven install”時,得到了:

[警告]此工件包含過濾器從未觸發以下模式:o'org.slf4j:slf4j-log4j12'

如何在“ index.xml”程序集文件中解決此問題?

我認為唯一的方法是通過不同的Maven配置文件定義不同的依賴策略。 建議參考hadoop Maven配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM