2015-10-15 48 views
3

我想從我的Java應用程序中調用NetLogo模型。我使用的是現在的sample codemaven項目中的netlogo headless

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新手,如果我失去了一些東西,我不明白...任何幫助超過welco我。

編輯

我試圖從我的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文件夾中:

<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> 

我唯一的問題現在是,具有基於星火項目,我已經有比更高Scala的依賴NetLogo one ...我剛剛刪除了Spark scala,Netlogo現在可以正常工作。

+0

https://github.com/NetLogo/NetLogo/issues/256。但在本地添加JAR應該可以工作。但是我沒有使用Maven,並且從錯誤信息中我不明顯地知道你遇到了什麼問題。請注意,NetLogo.jar不是自包含的 - 它取決於NetLogo的lib目錄中的所有JAR。 –

+0

我沒有得到討論的參考......你有在ccl的maven回購嗎?順便說一下,我有本地Netlogo和lib文件夾...但仍然有東西丟失,我猜... – user299791

+0

我們不這樣做,這就是爲什麼票仍然打開,你必須在本地添加的jar本地 –

回答

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>

+0

非常感謝你分享這個 – user299791

0

我設法與手動導入所有罐子lib文件夾中:

<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的問題,除非您有其他可以使用NetLogo版本的scala導入。在這種情況下,請參閱上面的@Seth Tisue的評論。