无法运行leJOS NXJ示例项目

时间:2011-01-30 15:29:11

标签: java lejos-nxj

我尝试在我的MAC OS X上安装leJOS NXJ并运行它的示例,但在我按照自己的意愿行事后export NXJ_Home Path file and etc。并安装netbeans插件并创建它的示例项目(Creating your own project using the Netbeans Plugin)。我也follow this structure并从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/

1 个答案:

答案 0 :(得分:1)

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

我的环境是WindowsXP和Netbeans 6.9.1。

leJOS安装在C:/ Program / leJOS NXJ

第一个项目:HelloWorld


我修复了,在项目根目录中放置了 build.properties文件中的 nxj.home var(此处为/ HelloWorld /和build.xml也在那里。)

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

希望有所帮助

乔。