简体   繁体   English

maven-shade-plugin 不包括声明为依赖项的 jar

[英]maven-shade-plugin is excluding jar that is declared as a dependency

I am using maven to package a shaded jar file.我正在使用 maven 打包一个带阴影的 jar 文件。 I trawled through the other posts on this, without finding an answer.我浏览了其他帖子,但没有找到答案。 I am not using provided as an element either.我也没有使用提供作为元素。

I include that log4j-core as a dependency in the pom.xml, but when maven-shade-plugin builds it excludes the classes in that dependency?我将该 log4j-core 作为依赖项包含在 pom.xml 中,但是当 maven-shade-plugin 构建时,它排除了该依赖项中的类? I downloaded V2.5 of the jar and checked, the package and class are in it.我下载了jar的V2.5并检查,包和类都在里面。

I had to exclude some org.slf4j classes but that should not affect this.我不得不排除一些 org.slf4j 类,但这不应该影响到这一点。

Here is the relevant part of the pom.xml这是 pom.xml 的相关部分

...
        <log4j.version>2.5</log4j.version>
</properties>
...
    <dependencies>
    <dependency>
        <groupId>de.ruedigermoeller</groupId>
        <artifactId>kontraktor</artifactId>
        <version>${kontraktor.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>de.ruedigermoeller</groupId>
        <artifactId>kontraktor-http</artifactId>
        <version>${kontraktor.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
...
        <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>${log4j.version}</version>
    </dependency>
...
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>uk.co.company.quokka.CompanyMain</mainClass>
                            </transformer>
                        </transformers>
                        <minimizeJar>true</minimizeJar>
                        <excludes>
                            <exclude>**/storage/*</exclude>
                            <exclude>**/data/*</exclude>
                            <exclude>**/web/*</exclude>
                        </excludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Here is the stack trace:这是堆栈跟踪:

ERROR StatusLogger Unable to create class org.apache.logging.log4j.core.impl.Log4jContextFactory specified in jar:file:/quokka-0.1-SNAPSHOT.jar!/META-INF/log4j-provider.properties
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
Properties file full path ../company.properties
Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.xnio.Xnio.<clinit>(Xnio.java:93)
    at io.undertow.Undertow.start(Undertow.java:97)
    at org.nustaq.kontraktor.remoting.http.Http4K.getServer(Http4K.java:94)
    at org.nustaq.kontraktor.remoting.http.builder.BldFourK.build(BldFourK.java:115)
    at uk.co.company.quokka.CompanyMain.main(CompanyMain.java:64)
Caused by: java.lang.IllegalArgumentException: Invalid logger interface org.xnio._private.Messages (implementation not found in sun.misc.Launcher$AppClassLoader@33909752)
    at org.jboss.logging.Logger$1.run(Logger.java:2254)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2227)
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214)
    at org.xnio._private.Messages.<clinit>(Messages.java:56)
    ... 5 more

最后我放弃了maven-shade-plugin并使用了maven-assembly-plugin,它似乎可以工作并最终得到一个可行的jar。

Due to the issue reported in https://issues.apache.org/jira/browse/LOG4J2-673 , I was also facing similar issue. 由于https://issues.apache.org/jira/browse/LOG4J2-673中报告的问题,我也遇到了类似的问题。

Thanks to this article http://www.codepreference.com/2017/02/how-to-fix-log4j2-problem-with-maven-shade-plugin.html which suggested to include/pass log4j-core and log4j-classic externally and it worked for me. 感谢这篇文章http://www.codepreference.com/2017/02/how-to-fix-log4j2-problem-with-maven-shade-plugin.html建议包含/传递log4j-core和log4j-classic外部,它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM