我尝试在我的 MAC OS X 上安装leJOS NXJ并运行它的示例,但是在我做了它想要的并导出 NXJ_Home Path 文件等之后。并安装 netbeans 插件并创建它的示例项目(使用 Netbeans 插件创建您自己的项目)。我也遵循这种结构,并从 intsall leJOS NXJ 安装的 lib 文件夹中替换了所需的 classes.jar。
我导出这 4 行:
My-macbook-pro:~ AR$ export NXJ_HOME=/Users/AR/Documents/Research-kar/JAVA/lejos_nxj
My-macbook-pro:~ AR$ export DYLD_LIBRARY_PATH=$NXJ_HOME/bin
My-macbook-pro:~ AR$ export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
My-macbook-pro:~ AR$ export PATH=$PATH:$JAVA_HOME/bin:$NXJ_HOME/binamirrezas-macbook-pro:~ AR$
这是 leJOS NXJ 示例代码:
package org.lejos.example;
import lejos.nxt.*;
/**
* Example leJOS Project with an ant build file
*
*/
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
Button.waitForPress();
}
}
这是相关的 build.xml 文件:
<project name="Example" default="uploadandrun">
<description>
org.lejos.example.HelloWorld build file
</description>
<!-- set properties for this build -->
<property environment = "env"/>
<property file="build.properties"/>
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="program" value="Example"/>
<property name="main.class" value="org.lejos.example.HelloWorld"/>
<property name="binary" value="${build}/${program}.nxj" />
<!-- deletes generated files -->
<target name="clean" description="clean up all generated files">
<delete dir="build"/>
</target>
<target name="compile" depends="clean"
description="compile the source " >
<!-- Compile the java code from ${src} to ${build} -->
<mkdir dir="${build}"/>
<javac srcdir="${src}" destdir="${build}">
<bootclasspath>
<pathelement location="${nxj.classes.home}/lib/classes.jar"/>
</bootclasspath>
</javac>
</target>
<target name="link" depends="compile"
description="link the binary " >
<!-- Link the binary and create a signature file -->
<java classname="js.tinyvm.TinyVM">
<arg value="--bootclasspath"/>
<arg path="${nxj.classes.jar}" />
<arg value="--classpath"/>
<arg path="${build}" />
<arg value="--writeorder" />
<arg value="LE" />
<arg value="${main.class}"/>
<arg value="-o"/>
<arg value="${binary}"/>
<arg value="-v"/>
<classpath>
<pathelement location="${nxj.jtools.jar}"/>
<pathelement location="${nxj.commons.jar}"/>
<pathelement location="${nxj.bcel.jar}"/>
</classpath>
</java>
</target>
<target name="upload" depends="link"
description="upload the binary" >
<java classname="lejos.pc.tools.NXJUpload" fork="true">
<jvmarg value="-Djava.library.path=${nxj.library.path}"/>
<jvmarg value="-Dnxj.home=${nxj.home}"/>
<arg value="${binary}"/>
<classpath>
<pathelement location="${nxj.jtools.jar}"/>
<pathelement location="${nxj.pctools.jar}"/>
<pathelement location="${nxj.pccomm.jar}"/>
<pathelement location="${nxj.commons.jar}"/>
<pathelement location="${nxj.bcel.jar}"/>
<pathelement location="${nxj.bluecove.jar}"/>
<pathelement location="${nxj.bluecove-gpl.jar}"/>
</classpath>
</java>
</target>
<target name="uploadandrun" depends="link"
description="upload and run the binary" >
<java classname="lejos.pc.tools.NXJUpload" fork="true">
<jvmarg value="-Djava.library.path=${nxj.library.path}"/>
<jvmarg value="-Dnxj.home=${nxj.home}"/>
<arg value="${binary}"/>
<arg value="-r"/>
<classpath>
<pathelement location="${nxj.jtools.jar}"/>
<pathelement location="${nxj.pctools.jar}"/>
<pathelement location="${nxj.pccomm.jar}"/>
<pathelement location="${nxj.commons.jar}"/>
<pathelement location="${nxj.bcel.jar}"/>
<pathelement location="${nxj.bluecove.jar}"/>
<pathelement location="${nxj.bluecove-gpl.jar}"/>
</classpath>
</java>
</target>
<!-- used only for modifying the Netbeans NXJPlugin -->
<target name="Zip for Netbeans" description="Zip the application to the sample project">
<property name="build.classes.dir" location="/build"/>
<property name="plugin" location="../NXJPlugin/src/nxjplugin/"/>
<zip basedir="." destfile="${plugin}/NXJSampleProject.zip">
<exclude name="**/build/"/>
<exclude name="**/bin/"/>
<exclude name="**/dist/"/>
<exclude name="**/nbproject/private/"/>
</zip>
</target>
</project>
这是 ide-file-targets.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir=".." name="org.lejos.example-IDE">
<target name="run-selected-file-in-src">
<fail unless="run.class">Must set property 'run.class'</fail>
<ant antfile="build.xml" target="uploadandrun">
<property name="main.class" value="${run.class}"/>
</ant>
</target>
<target name="compile-selected-files-in-src">
<ant antfile="build.xml" target="compile"/>
</target>
</project>
我收到此错误:
run-selected-file-in-src:
clean:
Deleting directory /Users/AR/Documents/NetBeansProjects/NXJSample/build
compile:
Created dir: /Users/AR/Documents/NetBeansProjects/NXJSample/build
Compiling 1 source file to /Users/AR/Documents/NetBeansProjects/NXJSample/build
/Users/AR/Documents/NetBeansProjects/NXJSample/src/org/lejos/example/HelloWorld.java:3: package lejos.nxt does not exist
import lejos.nxt.*;
/Users/AR/Documents/NetBeansProjects/NXJSample/src/org/lejos/example/HelloWorld.java:13: cannot find symbol
symbol : variable Button
location: class org.lejos.example.HelloWorld
Button.waitForPress();
^
2 errors
/Users/AR/Documents/NetBeansProjects/NXJSample/nbproject/ide-file-targets.xml:5: The following error occurred while executing this line:
/Users/AR/Documents/NetBeansProjects/NXJSample/build.xml:24: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)
[1]: http://lejos.sourceforge.net/