简体   繁体   English

Salesforce API罐的Maven阴影罐中的java.lang.NoClassDefFoundError

[英]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.

相关问题 Eclipse Maven使用外部Jar测试java.lang.NoClassDefFoundError - Eclipse Maven Test java.lang.NoClassDefFoundError with External Jar IntelliJ - Maven 添加外部 jar 文件但 java.lang.NoClassDefFoundError - IntelliJ - Maven adding external jar file but java.lang.NoClassDefFoundError 在Eclipse中使用Maven创建可执行jar-java.lang.NoClassDefFoundError - Create executable jar with maven in eclipse - java.lang.NoClassDefFoundError Maven的java.lang.noclassdeffounderror - java.lang.noclassdeffounderror for Maven java jar包含jars =&gt; java.lang.NoClassDefFoundError - &gt;如何包含.jar文件 - java Jar containing jars => java.lang.NoClassDefFoundError -> How to include .jar files 具有两个BouncyCastle罐的java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError with two BouncyCastle jars 为什么在使用POI jar的jar时出现java.lang.NoClassDefFoundError - Why I'm Getting java.lang.NoClassDefFoundError while using jar which use poi jars Maven: 无法使用 Maven 将本地 jar 打包到最终 jar 中,错误为 java.lang.NoClassDefFoundError - Maven: can not package local jar into final jar with maven and the error is java.lang.NoClassDefFoundError Java Jar文件的java.lang.NoClassDefFoundError - java.lang.NoClassDefFoundError for Java Jar File java -jar和java.lang.NoClassDefFoundError - java -jar and java.lang.NoClassDefFoundError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM