简体   繁体   English

带有Eclipse Project作为依赖项的Maven包导致NoClassDefFoundError

[英]Maven package with Eclipse Project as dependency leads to NoClassDefFoundError

Here is the situation. 这是情况。 I am developing a GUI Client for (historically) CLI based processes. 我正在为基于历史的CLI进程开发GUI客户端。 These processes are each under a Maven Project in Eclipse. 这些过程均在Eclipse中的Maven项目下。 My GUI is a separate Eclipse Maven Project. 我的GUI是一个单独的Eclipse Maven项目。 The GUI Project references the other projects in its pom.xml , the mvn package doesn't fail, yet when I run the project's ...-jar-with-dependencies.jar I get a NoClassDefFoundError for a child's project class. GUI项目在其pom.xml引用了其他项目, mvn package没有失败,但是当我运行项目的...-jar-with-dependencies.jar我得到了一个孩子项目类的NoClassDefFoundError

Here is my pom.xml 这是我的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>
  <artifactId>proto-xml-validator</artifactId>
  <organization>
    <name>SGcib</name>
    <url>https://cib.societegenerale.com/en/</url>
  </organization>
  <build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>com.sgcib.bacardi.tools.gui.ProtoXMLValidatorGui</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>
  </plugins>
</build>
  <dependencies>
  <!-- https://mvnrepository.com/artifact/com.miglayout/miglayout-swing -->
<dependency>
    <groupId>com.miglayout</groupId>
    <artifactId>miglayout-swing</artifactId>
    <version>5.0</version>
</dependency>

  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.11.1</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.11.1</version>
  </dependency>
  <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
  <dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.8</version>
  </dependency>
  <dependency>
      <groupId>org.codehaus.plexus</groupId>
      <artifactId>plexus-utils</artifactId>
      <version>1.1</version>
    </dependency>
    <dependency>
      <groupId>idea</groupId>
      <artifactId>ideaToolsUtils</artifactId>
      <version>1.2-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>bacardi</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <artifactId>pnl-loader</artifactId>
    </dependency>
</dependencies>
  <groupId>bacardi</groupId>
  <version>0.0.1-SNAPSHOT</version>
</project>

And here is the stack trace 这是堆栈跟踪

$ java -jar target/proto-xml-validator-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: idea/file/loader/runner/ValuationBVLoaderRunner
        at com.sgcib.bacardi.tools.gui.ProtoXMLValidatorGui.initialize(ProtoXMLValidatorGui.java:55)
        at com.sgcib.bacardi.tools.gui.ProtoXMLValidatorGui.<init>(ProtoXMLValidatorGui.java:33)
        at com.sgcib.bacardi.tools.gui.ProtoXMLValidatorGui$1.run(ProtoXMLValidatorGui.java:127)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: idea.file.loader.runner.ValuationBVLoaderRunner
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)

The class that triggers the NoClassDefFoundError is located under the pnl-loader artifactId in the bacardi groupId. 触发NoClassDefFoundError的类位于bacardi groupId中的bacardi pnl-loader artifactId下。

I have already set the scope to compile for the Project dependencies. 我已经设置了要针对Project依赖项进行compile的范围。

Does anyone know what I might be doing wrong ? 有人知道我可能做错了吗?

Thanks in advance. 提前致谢。

Solution to my problem: 解决我的问题的方法:

The thing was that, although my Eclipse Maven Project had the correct dependency references, it couldn't properly package them in the JAR. 事实是,尽管我的Eclipse Maven Project具有正确的依赖项引用,但它无法将其正确打包在JAR中。 Indeed, a project dependency is of no use to Maven (which doesn't know what an Eclipse project is, ofc). 确实,项目依赖对Maven没有用处(Maven不知道Eclipse项目是什么)。 Maven goes looking for compiled JARs in his repositories. Maven在他的存储库中寻找编译的JAR。 That's what @aka-one pointed out in the comments. 这就是@ aka-one在评论中指出的内容。 I had to mvn clean install the several projects that were necessary to build in order to finally package my project. 为了最终打包我的项目,我必须mvn clean install必要构建的几个项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM