【问题标题】:Add Dependencies to Maven from Custom Eclipse Version (Repast)从自定义 Eclipse 版本添加依赖项到 Maven (Repast)
【发布时间】:2017-10-04 23:40:07
【问题描述】:

我目前正在使用 Repast 进行模拟项目。这是一个自定义的 Eclipse 版本,带有用于实际模拟的内置库。

我现在想用这个制作一个 Maven 项目。但是,我不知道如何将 Repast-libraries 包含到我的 pom.xml 中,因为 mvnrepository 上既没有条目,也没有包含在我的项目文件夹中的库。它们都来自 repast 插件并驻留在我的 eclipse 安装中,如下所示:

Package Explorer View

这就是我的 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>
  <groupId>Simulation</groupId>
  <artifactId>Simulation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>Simulation</name>
  <url>http://maven.apache.org</url>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <outputDirectory>bin</outputDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>simulation.app.UserMain</mainClass>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> 
            <phase>package</phase> 
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <!-- some other dependencies that are required -->
  </dependencies>
</project>

我的类路径中对应的条目是这样的:

<classpathentry kind="con" path="REPAST_SIMPHONY_SUPPORT"/>

但是我如何把它放到我的 maven 项目中呢? 每当我运行 maven 构建过程时,生成的 JAR 都会以“NoClassDefFoundErrors”终止。当我用 WinRaR 打开 JAR-File 时,我发现repast 库不在其中。

有人知道如何解决这个问题吗?提前致谢!

【问题讨论】:

  • 是的,我知道那个帖子。但情况恰恰相反。他在问,如何将 maven 依赖项放入 repast 启动器,而不是将 repast-libraries 放入 maven 构建中。

标签: java eclipse maven dependencies classpath


【解决方案1】:

这是由于存在您的代码所依赖的类文件,并且它在编译时存在但在运行时找不到。查找构建时间和运行时类路径的差异。

你可以参考这个链接: https://dzone.com/articles/how-resolve-0

https://dzone.com/articles/how-resolve-1

【讨论】:

    【解决方案2】:

    正如SourceForge forum中所引用的:

    Eclipse Maven Managed Dependencies 中包含的 jars 不是 包含在与一个关联的默认启动器使用的类路径中 复食项目。因此,当有 Maven 时启动项目 Repast 搜索时,依赖项将导致 NoClassDefFoundError 通过类路径寻找注解。

    解决方法如下:

    添加 Eclipse Maven 托管 启动文件的依赖项(位于启动器/[项目名称] 模型.launch)。将以下行添加到类路径条目中:

    <listEntry value="&lt;?xml version=&quot;1.0&quot;
    encoding=&quot;UTF-8&quot;
    standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry
    containerPath=&quot;org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER&quot;
    path=&quot;3&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/>
    

    【讨论】:

    • 是的,我知道那个帖子。但情况恰恰相反。他在问,如何将 maven 依赖项放入 repast 启动器,而不是将 repast-libraries 放入 maven 构建中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-24
    • 2012-11-28
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    • 2010-09-13
    • 1970-01-01
    相关资源
    最近更新 更多