[英]Eclipse Maven Test java.lang.NoClassDefFoundError with External Jar
[英]java.lang.NoClassDefFoundError in Maven shaded jar for salesforce API jars
我有一個導入類的Apache Maven Java項目:
com.sforce.soap.enterprise.EnterpriseConnection
從IntelliJ運行項目時,執行代碼沒有問題。 但是,我希望能夠從命令行將項目作為陰影罐子運行。 我一直在用'mvn package'遮蓋罐子。 當我從命令行運行jar時,出現錯誤:
線程“主”中的異常java.lang.NoClassDefFoundError:com / sforce / soap / enterprise / EnterpriseConnection
我的pom包含依賴項:
<dependency>
<groupId>qa-integration.sfdc</groupId>
<artifactId>enterprise</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/enterprise-1.0.0.jar</systemPath>
</dependency>
<dependency>
<groupId>qa-integration.sfdc</groupId>
<artifactId>metadata</artifactId>
<version>1.0.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/metadata-1.0.0.jar</systemPath>
</dependency>
我的陰影執行如下所示:
<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>
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.sunrun.integration.sfdc.metadata.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
當我列出罐子的內容時,根本看不到任何Salesforce文件。
我遇到了這個問題,我的解決方案是將以下代碼段添加到我的pom.xml中:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>corrigo.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-jar-plugin</artifactId>-->
<!--<version>2.4</version>-->
<!--<configuration>-->
<!--<archive>-->
<!--<manifest>-->
<!--<mainClass>corrigo.Main</mainClass>-->
<!--</manifest>-->
<!--</archive>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
</build>
然后,您只需運行mvn package
。 這是可靠的資源: https : //www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.