首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven-shade-plugin排除了声明为依赖项的jar

maven-shade-plugin排除了声明为依赖项的jar
EN

Stack Overflow用户
提问于 2016-09-21 21:06:06
回答 1查看 1.5K关注 0票数 3

我正在使用maven打包一个带阴影的jar文件。我翻遍了其他关于这个问题的帖子,也没有找到答案。我也没有使用provided作为一个元素。

我将log4j- pom.xml作为依赖项包含在插件中,但是当maven-shade-plugin构建时,它会排除该依赖项中的类吗?我下载了jar的V2.5并检查了,包和类都在里面。

我不得不排除一些org.slf4j类,但这不应该影响这一点。

以下是pom.xml的相关部分

代码语言:javascript
复制
...
        <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>

下面是堆栈跟踪:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2016-09-27 19:28:58

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39617428

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档