[英]java.lang.NoClassDefFoundError in Maven shaded jar for salesforce API jars
I have an Apache Maven Java project that imports the class: 我有一个导入类的Apache Maven Java项目:
com.sforce.soap.enterprise.EnterpriseConnection com.sforce.soap.enterprise.EnterpriseConnection
When running the project from IntelliJ, I have no problems executing the code. 从IntelliJ运行项目时,执行代码没有问题。 However, I want to be able to run the project from the command line as a shaded jar.
但是,我希望能够从命令行将项目作为阴影罐子运行。 I have been shading the jar using 'mvn package'.
我一直在用'mvn package'遮盖罐子。 When I run the jar from the command line I am getting the error:
当我从命令行运行jar时,出现错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sforce/soap/enterprise/EnterpriseConnection 线程“主”中的异常java.lang.NoClassDefFoundError:com / sforce / soap / enterprise / EnterpriseConnection
My pom includes dependencies: 我的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>
My shade execution looks like the following: 我的阴影执行如下所示:
<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>
When I list the contents of the jar, I see no salesforce files at all. 当我列出罐子的内容时,根本看不到任何Salesforce文件。
I had this problem and my solution was to add the following snippet to my pom.xml: 我遇到了这个问题,我的解决方案是将以下代码段添加到我的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>
Then you just run mvn package
. 然后,您只需运行
mvn package
。 Here is a reliable resource: https://www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/ 这是可靠的资源: https : //www.mkyong.com/maven/how-to-create-a-jar-file-with-maven/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.