Standart bir maven projesinde maven-shade-plugin:2.4.3
ile çok garip bir yapı var. Maven paketi komutunu çalıştırırken her zaman mainClass
istisnasını bulamadık. Az önce bir maven-gölge-eklentisi örneği taklit aşağıya bakın:Maven gölge eklentisi 'mainClass' istisnasını bulamıyor musunuz?
<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.mkyong.core.utils</groupId>
<artifactId>dateUtils</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>dateUtils</name>
<url>http://maven.apache.org</url>
<properties>
<jdk.version>1.7</jdk.version>
<jodatime.version>2.5</jodatime.version>
<junit.version>4.11</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime.version}</version>
</dependency>
</dependencies>
<build>
<finalName>dateutils</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<!-- download source code in Eclipse, best practice -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
</configuration>
</plugin>
<!-- Set a compiler level -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<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>com.mkyong.core.utils.App</mainClass>
</transformer>
</transformers>
</configuration>
</plugin>
</plugins>
</build>
</project>
Bu seferki başarı çalıştırabilirsiniz. Sonra sadece bu gibi ana sınıfı adını ve diğer değiştirin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>xxxxxxx</mainClass>
</transformer>
</transformers>
</configuration>
</plugin>
eklenti hattı hakkında ebeveyn pom.xml
dosyası:
<pluginManagement>
<plugins>
<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>
</execution>
</executions>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</pluginManagement>
Yani modüller olacak ebeveyn uzanır, ama ne zaman paketin o istisna atar,
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade (default) on project analytics-sdk-storm-local: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:2.4.3:shade for parameter mainClass: Cannot find 'mainClass' in class org.apache.maven.plugins.shade.resource.AppendingTransformer -> [Help 1]
Ama neden happened.There maven bağımlılıkları ağaç programıyız: bahsedilen
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ xxxxx ---
[INFO] local:jar:1.0.1-SNAPSHOT
[INFO] +- org.apache.kafka:kafka_2.10:jar:0.8.1.1:compile
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | +- org.xerial.snappy:snappy-java:jar:1.1.2:compile
[INFO] | +- net.sf.jopt-simple:jopt-simple:jar:3.2:compile
[INFO] | +- org.scala-lang:scala-library:jar:2.10.1:compile
[INFO] | \- com.101tec:zkclient:jar:0.3:compile
[INFO] +- org.apache.storm:storm-core:jar:0.9.3:provided
[INFO] | +- org.clojure:clojure:jar:1.5.1:provided
[INFO] | +- clj-time:clj-time:jar:0.4.1:provided
[INFO] | +- joda-time:joda-time:jar:2.8.2:provided
[INFO] | +- compojure:compojure:jar:1.1.3:provided
[INFO] | +- org.clojure:core.incubator:jar:0.1.0:provided
[INFO] | +- org.clojure:tools.macro:jar:0.1.0:provided
[INFO] | +- clout:clout:jar:1.0.1:provided
[INFO] | +- ring:ring-core:jar:1.1.5:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] | +- hiccup:hiccup:jar:0.3.6:provided
[INFO] | +- ring:ring-devel:jar:0.3.11:provided
[INFO] | +- clj-stacktrace:clj-stacktrace:jar:0.2.2:provided
[INFO] | +- ring:ring-jetty-adapter:jar:0.3.11:provided
[INFO] | +- ring:ring-servlet:jar:0.3.11:provided
[INFO] | +- org.mortbay.jetty:jetty:jar:6.1.26:provided
[INFO] | +- org.mortbay.jetty:jetty-util:jar:6.1.26:provided
[INFO] | +- org.clojure:tools.logging:jar:0.2.3:provided
[INFO] | +- org.clojure:math.numeric-tower:jar:0.0.1:provided
[INFO] | +- org.clojure:tools.cli:jar:0.2.4:provided
[INFO] | +- commons-io:commons-io:jar:2.4:provided
[INFO] | +- org.apache.commons:commons-exec:jar:1.1:provided
[INFO] | +- commons-lang:commons-lang:jar:2.5:provided
[INFO] | +- com.googlecode.json-simple:json-simple:jar:1.1.1:provided
[INFO] | | \- junit:junit:jar:4.12:provided
[INFO] | | \- org.hamcrest:hamcrest-core:jar:1.3:provided
[INFO] | +- com.twitter:carbonite:jar:1.4.0:provided
[INFO] | +- com.esotericsoftware.kryo:kryo:jar:2.21:provided
[INFO] | +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:provided
[INFO] | +- org.ow2.asm:asm:jar:4.0:compile
[INFO] | +- com.esotericsoftware.minlog:minlog:jar:1.2:provided
[INFO] | +- org.objenesis:objenesis:jar:1.2:compile
[INFO] | +- com.twitter:chill-java:jar:0.3.5:provided
[INFO] | +- org.yaml:snakeyaml:jar:1.16:provided
[INFO] | +- commons-logging:commons-logging:jar:1.1.3:provided
[INFO] | +- commons-codec:commons-codec:jar:1.9:provided
[INFO] | +- com.googlecode.disruptor:disruptor:jar:2.10.1:provided
[INFO] | +- org.jgrapht:jgrapht-core:jar:0.9.0:provided
[INFO] | +- ch.qos.logback:logback-classic:jar:1.1.5:provided
[INFO] | +- ch.qos.logback:logback-core:jar:1.0.13:provided
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.7.16:provided
[INFO] | \- jline:jline:jar:2.11:compile
[INFO] +- org.apache.storm:storm-kafka:jar:0.9.3:compile
[INFO] | \- org.apache.curator:curator-framework:jar:2.5.0:compile
[INFO] | +- org.apache.curator:curator-client:jar:2.5.0:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] | | \- io.netty:netty:jar:3.7.0.Final:compile
[INFO] | \- com.google.guava:guava:jar:19.0:compile
[INFO] +- so.sao.analytics:analytics-sdk-common:jar:1.0.1-SNAPSHOT:compile
[INFO] | +- com.esotericsoftware:kryo:jar:3.0.3:compile
[INFO] | | +- com.esotericsoftware:reflectasm:jar:1.10.1:compile
[INFO] | | \- com.esotericsoftware:minlog:jar:1.3.0:compile
[INFO] | \- org.mapdb:mapdb:jar:2.0-beta12:compile
[INFO] \- so.sao.analytics:analytics-sdk-storm-common:jar:1.0.1-SNAPSHOT:compile
Neden başarısız olduğunu bilmiyorum. Şimdi sadece kodu ek açıklama. Bununla tanıştın mı, göster bana, teşekkürler.
evet, benim ana modülü 'pom.xml' dosyasında aynı yapılandırmak orada vardı şikayet ediyor. Ayrıca resmi kullanım [maven-gölge-eklenti/örnekler/kaynak-transformers] (https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer) başvurmuştu. Ama yine de başarısız oldu. ve diğer projemde bu ayar iyi çalışıyor. Bu çok tuhaf. – elkan1788
@ elkan1788 Güncellenmiş yanıtıma bir göz atın. Belki de gerçekte kullandığınız 'pom.xml'de bir çeşit yazım hatası var. – SubOptimal
Teşekkürler, 'pom.xml' dosyamdaki çekirdek demo ile aynıydı, yükseltme sorgumu görebilirsiniz. Ayrıca kendinizinki gibi garip hissediyorum, neden AppendingTransformer istisnası atar. Belki de projemde başka bir hata ayarı var mı? – elkan1788