gpt4 book ai didi

java - Maven 项目中的 netlogo headless

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:17:33 25 4
gpt4 key购买 nike

我正在尝试从我的 Java 应用程序调用 NetLogo 模型。我现在正在使用 sample code :

public static void main(String[] argv) {

HeadlessWorkspace workspace = HeadlessWorkspace.newInstance();
try {
workspace.open("models/Sample Models/Earth Science/Fire.nlogo");
workspace.command("set density 62");
workspace.command("random-seed 0");
workspace.command("setup");
workspace.command("repeat 50 [ go ]");
System.out.println(workspace.report("burned-trees"));
workspace.dispose();
} catch (IOException | CompilerException | LogoException | InterruptedException ex) {
ex.printStackTrace();
}
}

我已经在我的 Netbeans 项目中添加了依赖项,但是当我尝试运行它时,我得到:

------------------------------------------------------------------------
Building JAGO3 1.3
------------------------------------------------------------------------
The POM for org.nlogo:NetLogo:jar:5.2 is missing, no dependency information available

COMPILATION ERROR :
-------------------------------------------------------------
com/digitaldust/jago3/NetLogoManager.java:[16,55] error: cannot access ScalaObject
1 error

此代码已添加到我的 POM 中:

<dependency>
<groupId>org.nlogo</groupId>
<artifactId>NetLogo</artifactId>
<version>5.2</version>
<scope>compile</scope>
<type>jar</type>
</dependency>

看起来 NetLogo 没有 POM,即使它被添加为依赖项......无论如何,作为一个 Maven 新手,我不明白我是否遗漏了什么......欢迎任何帮助。

编辑

我已尝试使用以下代码片段将 NetLogo 文件夹中的 NetLogo.jar 添加为本地依赖项:

<dependency>
<groupId>org.nlogo</groupId>
<artifactId>NetLogo</artifactId>
<version>5.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/NetLogo.jar</systemPath>
</dependency>

我能够从我当前的 NetLogo 安装加载依赖项,但我仍然收到(不同的)错误:

--- maven-resources-plugin:2.5:resources (default-resources) @ JAGO3 ---
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 26 resources

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ JAGO3 ---
Nothing to compile - all classes are up to date

--- exec-maven-plugin:1.2.1:exec (default-cli) @ JAGO3 ---
Exception in thread "main" java.lang.NoClassDefFoundError: org/nlogo/api/CompilerException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.privateGetMethodRecursive(Class.java:3040)
at java.lang.Class.getMethod0(Class.java:3010)
at java.lang.Class.getMethod(Class.java:1776)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.nlogo.api.CompilerException
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

EDIT2

我设法手动导入 lib 文件夹中的所有 jar:

<dependency>
<groupId>org.nlogo</groupId>
<artifactId>netlogo</artifactId>
<version>5.2</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.objectweb.asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3.1</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.commons.codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.sun.gluegen</groupId>
<artifactId>gluegen-rt</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.httpclient</groupId>
<artifactId>httpclient</artifactId>
<version>4.2</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.httpcore</groupId>
<artifactId>httpcore</artifactId>
<version>4.2</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.httpmime</groupId>
<artifactId>httpmime</artifactId>
<version>4.2</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.jhotdraw</groupId>
<artifactId>jhotdraw</artifactId>
<version>6.0b1</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax.media</groupId>
<artifactId>jmf</artifactId>
<version>2.1.1e</version>
</dependency>
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>mrj</groupId>
<artifactId>mrjadapter</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.parboiled</groupId>
<artifactId>parboiled-core</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.parboiled</groupId>
<artifactId>parboiled-java</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.13.6</version>
</dependency>
<dependency>
<groupId>org.devzendo</groupId>
<artifactId>Quaqua</artifactId>
<version>7.3.4</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.jdesktop.layout</groupId>
<artifactId>swing-layout</artifactId>
<version>7.3.4</version>
</dependency>

我现在唯一的问题是,有一个基于 Spark 的项目,我已经有一个比 NetLogo 更高的 scala 依赖......我刚刚删除了 Spark scala,Netlogo 现在工作正常。

最佳答案

NetLogo 6.0+ 现已在 bintray 上可用但是仍然需要做一些工作才能通过 Maven 正确下载它。首先,您必须将 bintray 存储库添加到 Maven - 作为远程存储库 (https://dl.bintray.com/netlogo/NetLogo-JVM) 或直接添加到您的 ~/.m2/settings.xml文件。


<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-netlogo-NetLogo-JVM</id>
<name>bintray</name>
<url>http://dl.bintray.com/netlogo/NetLogo-JVM</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-netlogo-NetLogo-JVM</id>
<name>bintray-plugins</name>
<url>http://dl.bintray.com/netlogo/NetLogo-JVM</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
</activeProfiles>
</settings>

然后将以下内容添加到您的 pom.xml排除通过 Scala 解析器组合器模块填充的缺失解析器依赖项。


<dependency>
<groupId>org.nlogo</groupId>
<artifactId>netlogo</artifactId>
<version>6.0.1</version>
<exclusions>
<exclusion>
<groupId>org.nlogo</groupId>
<artifactId>parser</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.13.6</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
<version>5.0.3</version>
</dependency>
<dependency>
<groupId>org.scala-lang.modules</groupId>
<artifactId>scala-parser-combinators_2.12</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.parboiled</groupId>
<artifactId>parboiled_2.12</artifactId>
<version>2.1.4</version>
</dependency>

关于java - Maven 项目中的 netlogo headless ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33157927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com