netlogo在maven项目中无头

时间:2015-10-15 20:27:45

标签: java maven pom.xml netlogo

我试图从我的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新手,我不明白我是否遗漏了某些东西......任何帮助都不仅仅是欢迎。< / p>

修改

我尝试使用此代码段从我的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现在运行正常。

2 个答案:

答案 0 :(得分:2)

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>

答案 1 :(得分:0)

我设法用以下方法手动导入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>  

如果您使用的是NetBeans,则必须右键单击并为项目POM创建的每个节点“手动导入工件”。这应该解决Maven的问题,除非你有其他scala导入与NetLogo使用的版本抱怨。在这种情况下,请参阅@Seth Tisue上面的评论。