我尝试在我的MAC OS X上安装leJOS NXJ并运行它的示例,但是在执行它想要的操作后,又export NXJ_Home Path file and etc了。并安装netbeans插件并创建它示例项目(Creating your own project using the Netbeans Plugin)。我也follow this structure并从insall 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/

最佳答案

有点晚了,但可能像我这样的人正在寻找解决方案。我是leJOS,Netbeans和Java的新手(今晚开始)。

我的环境是带有Netbeans 6.9.1的WindowsXP。

leJOS安装在C:/ Programme / leJOS NXJ中

第一个项目:HelloWorld



我通过在项目根目录中的build.properties文件中设置nxj.home var来修复此问题(在这里,还存在/ HelloWorld /和build.xml)。

nxj.home必须指向leJOS安装路径。就我而言:
nxj.home = C:/ Programme / leJOS NXJ

希望能帮助到你

10-06 08:40