我发现某人的pom.xml中使用了maven-shade-plugin.我之前从未使用过maven-shade-plugin(我是Maven n00b),所以我试着理解使用它的原因及其作用.
我查看了Maven文档,但是我无法理解这句话:
"这个插件提供了将工件打包在超级jar中的功能,包括它的依赖关系和阴影 - 即重命名 - 一些依赖项的包." 页面上的文档似乎不是新手友好的.
什么是"超级罐子?" 为什么有人想制作一个?重命名依赖项包的重点是什么?我试图通过maven-shade-plugin apache页面上的示例,例如"为Uber Jar选择内容",但我仍然无法理解"着色"所取得的成就.
任何指向说明性示例/用例的指针(解释为什么在这种情况下需要着色 - 解决了什么问题)将不胜感激.最后,我什么时候应该使用maven-shade-plugin?
我阅读了文档,没有发现任何有关它的用途的内容.
maven shade插件正在创建一个名为dependency-reduced-pom.xml的文件,还有artifactname-shaded.jar并将它们放在基本目录中.
这是一个错误吗?应该在目标目录中.任何解决方法?
将Maven jFree依赖项添加到现有应用程序后,我无法执行创建的jar.
我得到的唯一错误消息如下:
java -jar target/com.company.product-1.0.0-SNAPSHOT.jar
Error: Invalid or corrupt jarfile target/com. company.product-1.0.0-SNAPSHOT.jar
Run Code Online (Sandbox Code Playgroud)
完整pom.xml
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion
<groupId>com.mycompany</groupId>
<artifactId>com.mycompany.test</artifactId>
<name>${project.artifactId}</name>
<version>1.0.0-SNAPSHOT</version>
<properties>
<java-version>1.7</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.springframework.data-version>1.0.3.RELEASE</org.springframework.data-version>
<org.springframework.ws-version>2.0.4.RELEASE</org.springframework.ws-version>
<org.springframework.ws.oxm-version>1.5.10</org.springframework.ws.oxm-version>
<org.aspectj-version>1.6.12</org.aspectj-version>
<org.slf4j-version>1.5.10</org.slf4j-version>
<selenium-java-version>2.25.0</selenium-java-version>
<browser-mob-version>2.0-beta-6</browser-mob-version>
</properties>
<dependencies>
<!-- Hint A: If we delete this dependency it works -->
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.14</version>
<exclusions>
<exclusion>
<artifactId>itext</artifactId>
<groupId>com.lowagie</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>de.schlichtherle.io</groupId>
<artifactId>truezip</artifactId>
<version>6.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>apache-log4j-extras</artifactId>
<version>1.1</version>
</dependency>
<!-- Caching …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Maven将我的测试类打包到一个带有依赖项的可执行jar中,但我很难做到这一点.
到目前为止这是我的pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>executable-tests</name>
<dependencies>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.21.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>cucumber-tests</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cucumber.cli.Main</mainClass>
</transformer>
</transformers>
<artifactSet>
<includes>
<include>info.cukes:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.c0deattack</groupId>
<artifactId>executable-tests</artifactId>
<version>1.0</version>
<type>test-jar</type>
</dependency>
</dependencies>
</plugin> …
Run Code Online (Sandbox Code Playgroud) 有谁知道我的maven构建发生了什么?我收到了很多重复的警告.
[WARNING] We have a duplicate org/apache/commons/logging/impl/LogFactoryImpl$1.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/LogFactoryImpl.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/NoOpLog.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/SimpleLog$1.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/SimpleLog.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
[WARNING] We have a duplicate org/apache/commons/logging/impl/Jdk14Logger.class in /home/shengjie/.m2/repository/commons-logging/commons-logging-api/1.0.4/commons-logging-api-1.0.4.jar
Run Code Online (Sandbox Code Playgroud)
我查看了我当地的m2 repo,我在commons-logging-api jar,LogFactoryImpl.class和LogFactoryImpl $ 1.class中有两个类.与警告中提到的所有类相同.
有一点需要提一下,我在我的pom.xml中使用了shade插件.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers> …
Run Code Online (Sandbox Code Playgroud) 我有一个基于Maven的Spring-WS客户端项目,我想打包成一个jar.在eclipse中,一切都运行正常.当我尝试将其打包为可执行jar时,我得到ClassNotFound异常,因为Spring jar没有包含在我的应用程序jar中.
所以我添加了maven-shade-plugin来包含我的应用程序jar中的所有依赖项.当我查看我的app jar时,我看到包含所有依赖项的所有类文件(所有库jar都被爆炸).
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.cws.cs.Client</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
我的问题是在打包过程中,我的多个spring依赖项有不同的META-INF/spring.schemas文件相互覆盖.因此,我的最后一个jar有一个不完整的spring.schemas文件.
因此,当我尝试运行我的可执行jar时,我收到Spring错误消息,因为spring.schemas文件不完整(Spring-WS的jar覆盖了Spring-core的spring.schemas文件),因此无法找到文件.
我的可执行jar的META-INF/spring.schemas:
http\://www.springframework.org/schema/web-services/web-services-1.5.xsd=/org/springframework/ws/config/web-services-1.5.xsd
http\://www.springframework.org/schema/web-services/web-services-2.0.xsd=/org/springframework/ws/config/web-services-2.0.xsd
http\://www.springframework.org/schema/web-services/web-services.xsd=/org/springframework/ws/config/web-services-2.0.xsd
Run Code Online (Sandbox Code Playgroud)
而不是Spring-beans.jar META-INF/spring.schemas:
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
Run Code Online (Sandbox Code Playgroud)
我很难过.我不确定是否/如何将所有内容打包为单个可执行jar.我不知道这是一个阴影插件配置问题,还是我试图做一些不可能的事情.我不得不手动创建自己的spring.schemas文件(其他的串联)似乎是不正确的.
我可能有点跳了一下枪.在挖掘插件的更多信息时,我注意到我之前错过的AppendingTransformer.但是,我关心的是如何知道哪些其他文件有同样的问题?我发现/抓住了这个特殊的Spring问题.我不知道任何其他可能正在做类似事情的库......
任何建议,将不胜感激.
我有应用程序,当我从maven log4j2运行时它正在工作:
mvn exec:java -Dexec.args=...
Run Code Online (Sandbox Code Playgroud)
但是当我将jar作为独立应用程序运行时,它会显示错误:
java -jar
Run Code Online (Sandbox Code Playgroud)
日志:
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at …
Run Code Online (Sandbox Code Playgroud) 所以这是我的问题...
我正在使用 maven-shade 插件将 Spring Boot 应用程序打包到 uber jar 中。很简单吧?好吧,除了最近我在结尾处收到以下警告mvn clean package
:
[WARNING] Discovered module-info.class. Shading will break its strong encapsulation.
这实际上并没有破坏任何东西,但我是一个完美主义者,这让我发疯了吗?我该如何摆脱它?我尝试了很多东西,但没有成功。
请帮忙 :(
这是我的项目POM(链接到粘贴,所以你可以右键单击>另存为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>
<groupId>com.zybnet</groupId>
<artifactId>excel-reporter</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>mvn1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.6.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.build.sourceDirectory}</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<finalName>${artifactId}-${version}-tmp</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers> …
Run Code Online (Sandbox Code Playgroud) maven ×9
java ×8
build ×1
dependencies ×1
jar ×1
jfreechart ×1
log4j2 ×1
module-info ×1
spring ×1
spring-ws ×1
uberjar ×1