ant build.xml does not exist. Build failed - java

I am a beginner in Ant and GWT and I was creating a new Ant project in GWT by following the steps mentioned on this GWT page: webAppCreator under the Creating an Ant project section. I was able to create this project successfully but I got the error build.xml does not exist! in the Command Prompt log. I am unable to fix this problem even after following all the steps mentioned here : ant build.xml file doesn't exist.
Here is my Command Prompt log:
C:\Users\TEST>webAppCreator -junit D:\SELENIUM\junit-4.10.jar -out foo com.example.foo.Foo
Generating from templates: [sample, eclipse, readme, _eclipse-test, _sample-test, ant]
Created directory foo
Created directory foo\src
Created directory foo\src\com\example\foo
Created directory foo\src\com\example\foo\client
Created directory foo\src\com\example\foo\server
Created directory foo\src\com\example\foo\shared
Created directory foo\test
Created directory foo\test\com\example\foo
Created directory foo\war
Created directory foo\war\WEB-INF
Created directory foo\test\com\example\foo\client
Created file foo\src\com\example\foo\Foo.gwt.xml
Created file foo\src\com\example\foo\client\GreetingService.java
Created file foo\src\com\example\foo\client\GreetingServiceAsync.java
Created file foo\src\com\example\foo\client\Foo.java
Created file foo\src\com\example\foo\server\GreetingServiceImpl.java
Created file foo\src\com\example\foo\shared\FieldVerifier.java
Created file foo\war\WEB-INF\web.xml
Created file foo\war\Foo.css
Created file foo\war\Foo.html
Created file foo\war\favicon.ico
Created file foo\.classpath
Created file foo\.project
Created file foo\Foo.launch
Created file foo\README.txt
Created file foo\FooSuite-dev.launch
Created file foo\FooSuite-prod.launch
Created file foo\test\com\example\foo\FooJUnit.gwt.xml
Created file foo\test\com\example\foo\FooSuite.java
Created file foo\test\com\example\foo\client\FooTest.java
Created file foo\build.xml
C:\Users\TEST>ant build
Buildfile: build.xml does not exist!
Build failed
C:\Users\TEST>ant devmode
Buildfile: build.xml does not exist!
Build failed
Here is my build.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<project name="Foo" default="build" basedir=".">
<!-- Arguments to gwtc and devmode targets -->
<property name="gwt.args" value="" />
<!-- Configure path to GWT SDK -->
<property name="gwt.sdk" location="D:/GWT/gwt-2.8.1/gwt-2.8.1" />
<path id="project.class.path">
<pathelement location="war/WEB-INF/classes"/>
<pathelement location="${gwt.sdk}/gwt-user.jar"/>
<pathelement location="${gwt.sdk}/gwt-dev.jar"/>
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA.jar"/>
<pathelement location="${gwt.sdk}/validation-api-1.0.0.GA-sources.jar"/>
<fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
<!-- Add any additional non-server libs (such as JUnit) here -->
</path>
<target name="libs" description="Copy libs to WEB-INF/lib">
<mkdir dir="war/WEB-INF/lib" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
<copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet-deps.jar" />
<!-- Add any additional server libs that need to be copied -->
</target>
<target name="javac" depends="libs" description="Compile java source to bytecode">
<mkdir dir="war/WEB-INF/classes"/>
<javac srcdir="src" includes="**" encoding="utf-8"
destdir="war/WEB-INF/classes"
source="1.7" target="1.7" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
<copy todir="war/WEB-INF/classes">
<fileset dir="src" excludes="**/*.java"/>
</copy>
</target>
<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler" maxmemory="512m">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
</classpath>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
<arg line="${gwt.args}"/>
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="devmode" depends="javac" description="Run development mode (pass -Dgwt.args=-nosuperDevMode to fallback to classic DevMode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.DevMode" maxmemory="1g">
<classpath>
<pathelement location="src"/>
<path refid="project.class.path"/>
<pathelement location="${gwt.sdk}/gwt-codeserver.jar"/>
</classpath>
<arg value="-startupUrl"/>
<arg value="Foo.html"/>
<arg line="-war"/>
<arg value="war"/>
<!-- Additional arguments like -style PRETTY, -logLevel DEBUG or -nosuperDevMode -->
<arg line="${gwt.args}"/>
<arg value="com.example.foo.Foo"/>
<arg value="com.example.foo.Foo"/>
</java>
</target>
<target name="javac.tests" depends="javac" description="Compiles test code">
<javac srcdir="test" includes="**" encoding="utf-8"
source="1.7" target="1.7" nowarn="true"
destdir="war/WEB-INF/classes"
debug="true" debuglevel="lines,vars,source">
<classpath location="D:\SELENIUM\junit-4.10.jar"/>
<classpath refid="project.class.path"/>
</javac>
</target>
<target name="test.dev" depends="javac.tests" description="Run development mode tests">
<mkdir dir="reports/htmlunit.dev" />
<junit fork="yes" printsummary="yes" haltonfailure="yes" maxmemory="256m">
<sysproperty key="gwt.args" value="-devMode -logLevel WARN -war www-test" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA.jar" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA-sources.jar" />
<pathelement location="D:\SELENIUM\junit-4.10.jar" />
</classpath>
<batchtest todir="reports/htmlunit.dev" >
<fileset dir="test" >
<include name="**/*Suite.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test.prod" depends="javac.tests" description="Run production mode tests">
<mkdir dir="reports/htmlunit.prod" />
<junit fork="yes" printsummary="yes" haltonfailure="yes" maxmemory="256m">
<sysproperty key="gwt.args" value="-logLevel WARN -war www-test" />
<sysproperty key="java.awt.headless" value="true" />
<classpath>
<pathelement location="src" />
<pathelement location="test" />
<path refid="project.class.path" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA.jar" />
<pathelement location="D:/GWT/gwt-2.8.1/gwt-2.8.1/validation-api-1.0.0.GA-sources.jar" />
<pathelement location="D:\SELENIUM\junit-4.10.jar" />
</classpath>
<batchtest todir="reports/htmlunit.prod" >
<fileset dir="test" >
<include name="**/*Suite.java" />
</fileset>
</batchtest>
<formatter type="plain" />
<formatter type="xml" />
</junit>
</target>
<target name="test" description="Run development and production mode tests">
<antcall target="test.dev" />
<antcall target="test.prod" />
</target>
<target name="build" depends="gwtc" description="Build this project" />
<target name="war" depends="build" description="Create a war file">
<zip destfile="Foo.war" basedir="war"/>
</target>
<target name="clean" description="Cleans this project">
<delete dir="war/WEB-INF/classes" failonerror="false" />
<delete dir="war/foo" failonerror="false" />
</target>
</project>
Can someone please help me to fix this issue?

It seems your build.xml is created in a foo folder.
See this output:
Created file foo\build.xml
Go to the foo directory and then run ant.

C:\Users\TEST>ant build
Buildfile: build.xml does not exist!
Build failed
It means build file is absent in TEST directory. Checking your logs you have one in the :\Users\TEST\foo. So you should navigate into foo than try command via terminal one more time.

if you are on Mac :
brew install ant;
brew install ivy;
ant ivy-bootstrap ;
then go to top of ant project;
run ant

Related

Build Successfully but not running junit files using Apache Ant

I am new in Apache ant to build the project. In my Project i used MySQL,junit and hibernate library. I am working on bitbucket pipelines so some suggest use to ant. So i am creating the build.xml file and in there the proecess is clean,build,run junit test case. I did many research how to learn these things but i am stuck in some place. I am success in clean the directory and build also but i am stuck to check junit failure test case. I tried to run these test case in eclipse it shows that test case fail but if i run through ant it always say build successfully. I will provide my project structure .
+HiberTest
--HTest
--lib
--mysql
--junit
-- Hibernate..... so many library
--src
-com
-test
**so many junit files**
-com
-utils
**so many files**
--classpath
--.settings
--.project
**and many more files**
--build.xml
Here is my build.xml files
<project basedir="." default="junit" name="Hibernate test">
<property name="debuglevel" value="source,lines,vars" />
<property name="src.dir" location="HTest/src" />
<property name="build.dir" location="HTest/bin" />
<property name="target" value="1.8" />
<property name="source" value="1.8" />
<property name="test.dir" value="HTest/bin/com/test" />
<path id="classpath">
<pathelement location="bin" />
<pathelement location="HTest/lib/junit3.8.1.jar" />
<pathelement location="HTest/lib/antlr-2.7.7.jar" />
<pathelement location="HTest/lib/byte-buddy-1.10.7.jar" />
<pathelement location="HTest/lib/classmate-1.5.1.jar" />
<pathelement location="HTest/lib/dom4j-2.1.1.jar" />
<pathelement location="HTest/lib/FastInfoset-1.2.15.jar" />
<pathelement location="HTest/lib/hibernate-commons-annotations-5.1.0.Final.jar" />
<pathelement location="HTest/lib/hibernate-core-5.4.11.Final.jar" />
<pathelement location="HTest/lib/istack-commons-runtime-3.0.7.jar" />
<pathelement location="HTest/lib/jandex-2.1.1.Final.jar" />
<pathelement location="HTest/lib/javassist-3.24.0-GA.jar" />
<pathelement location="HTest/lib/javax.activation-api-1.2.0.jar" />
<pathelement location="HTest/lib/javax.persistence-api-2.2.jar" />
<pathelement location="HTest/lib/jaxb-api-2.3.1.jar" />
<pathelement location="HTest/lib/jaxb-runtime-2.3.1.jar" />
<pathelement location="HTest/lib/jboss-logging-3.3.2.Final.jar" />
<pathelement location="HTest/lib/jboss-transaction-api_1.2_spec-1.1.1.Final.jar" />
<pathelement location="HTest/lib/mysql-connector-java-5.1.48.jar" />
<pathelement location="HTest/lib/stax-ex-1.8.jar" />
<pathelement location="HTest/lib/txw2-2.3.1.jar" />
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="init" depends="clean">
<mkdir dir="${build.dir}" />
<copy includeemptydirs="false" todir="${build.dir}">
<fileset dir="${src.dir}">
<exclude name="**/*.launch" />
<exclude name="**/*.java" />
</fileset>
</copy>
</target>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}" />
<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}" includeantruntime="false" source="${source}" target="${target}">
<src path="${src.dir}" />
<classpath refid="classpath" />
</javac>
</target>
<target name="junit" depends="build-project">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
<path refid="classpath" />
<pathelement location="HTest/src/com/utils" />
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.dir}" includes="*.java" />
</batchtest>
</junit>
</target>
</project>
It always gives me this output:-
clean:
[delete] Deleting directory F:\Repository\Agile\HiberTest\HTest\bin
init:
[mkdir] Created dir: F:\Repository\Agile\HiberTest\HTest\bin
[copy] Copying 1 file to F:\Repository\Agile\HiberTest\HTest\bin
build-project:
[echo] Hibernate test: F:\Repository\Agile\HiberTest\build.xml
[javac] Compiling 3 source files to F:\Repository\Agile\HiberTest\HTest\bin
junit:
BUILD SUCCESSFUL
Total time: 1 second
I want to check that if junit test fail then stop the build process and if passes all without error and then i want to create executable jar files
Thanks in advance
The build starts in "build" and the hierarchical never call junit. Try to change:
<target depends="build-project" name="junit" />

JAR File NoClassDefFoundError

I am trying to build a runnable JAR file of a project by using build.xml file and the prompt code
cd <the directory of you application>
ant -f bin/build.xml jar
But I have exceptions when I run the JAR because I cannot add the external JAR.
the build.xml is as follows:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!--
This file was generated by Jason 1.3.9-alpha
http://jason.sf.net
Ocak 11, 2014 - 01:09:12
-->
<project name ="virtualClassroom"
basedir=".."
default="run">
<property name="mas2j.project.file" value="virtualClassroom.mas2j"/>
<property name="debug" value=""/> <!-- use "-debug" to run in debug mode -->
<property name="build.dir" value="${basedir}/bin/classes" />
<property name="jasonJar" value="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9\lib\jason.jar"/>
<property name="JavaCsBridgeJar" value="C:\Users\Emre\Desktop\MasterThesis-BDI\virtualClassroom\lib\JavaCsBridge.jar"/>
<path id="project.classpath">
<pathelement location="${basedir}"/>
<pathelement location="${build.dir}"/>
<pathelement location="${JavaCsBridgeJar}"/>
<pathelement location="${jasonJar}"/>
<fileset dir="${basedir}/lib" > <include name="*.jar" /> </fileset>
</path>
<!-- tasks the user can override in his/her c-build.xml script -->
<target name="user-init">
</target>
<target name="user-end">
</target>
<target name="init">
<mkdir dir="${build.dir}" />
<antcall target="user-init" />
</target>
<target name="compile" depends="init">
<condition property="srcdir" value="${basedir}/src/java" else="${basedir}" >
<available file="${basedir}/src/java" />
</condition>
<javac srcdir="${srcdir}" destdir="${build.dir}" debug="true" optimize="true" includeantruntime="false" >
<classpath refid="project.classpath"/>
</javac>
</target>
<target name="jar" depends="compile">
<delete file="${ant.project.name}.jar" />
<copy file="${jasonJar}" tofile="${ant.project.name}.jar" />
<copy file="${JavaCsBridge}" tofile="${ant.project.name}.jar" />
<copy file="${mas2j.project.file}" tofile="default.mas2j" />
<jar update="yes" jarfile="${ant.project.name}.jar" >
<fileset dir="${basedir}">
<include name="**/*.asl" />
<include name="**/*.mas2j" />
</fileset>
<fileset dir="${build.dir}">
<include name="**/*.class" />
</fileset>
<manifest>
<attribute name="Main-Class" value="jason.infra.centralised.RunCentralisedMAS"/>
</manifest>
</jar>
<delete file="default.mas2j" />
</target>
<target name="jnlp" depends="jar" >
<mkdir dir="${basedir}/${ant.project.name}-jws"/>
<java classname="jason.infra.centralised.CreateJNLP"
failonerror="true" fork="yes" dir="${basedir}/${ant.project.name}-jws" >
<classpath refid="project.classpath"/>
<arg line="${ant.project.name} ${mas2j.project.file}"/>
</java>
<copy todir="${basedir}/${ant.project.name}-jws" failonerror="no">
<fileset dir="${basedir}/lib" includes="**/*.jar" />
<fileset dir="${basedir}" includes="${ant.project.name}.jar" />
<fileset dir="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9/src/images" includes="Jason-GMoreau-Icon.jpg" />
</copy>
<signjar jar="${basedir}/${ant.project.name}-jws/${ant.project.name}.jar" alias="jason"
storepass="rbjhja" keypass="rbjhja" keystore="C:\Users\Emre\Desktop\MasterThesis-BDI\Jason-1.3.9\Jason-1.3.9/src/jasonKeystore" />
<echo message="**" />
<echo message="** Java Web Start application created in directory ${ant.project.name}-jws" />
<echo message="** Update the codebase (in the second line of the .jnlp file)" />
<echo message="** with the URL where you will upload the application." />
<echo message="**" />
</target>
<target name="run" depends="compile" >
<echo message="Running project ${ant.project.name}" />
<java classname="jason.infra.centralised.RunCentralisedMAS"
failonerror="true" fork="yes" dir="${basedir}" >
<classpath refid="project.classpath"/>
<arg line="${mas2j.project.file} ${debug} "/>
<!-- jvmarg line="-Xmx500M -Xss8M"/ -->
</java>
<antcall target="user-end" />
</target>
<target name="clean" >
<delete failonerror="no" includeEmptyDirs="true" verbose="true">
<fileset dir="${basedir}" includes="**/*.class"/>
</delete>
</target>
</project>
Do anyone know what to do?
Thanks
Firstly, you need to tell us exactly which class is giving a NoClassDefFoundError
As a generic answer, the explanation is that the particular class was available during compile time but missing during runtime. This is a common issue with jar executables.
Solution : Either include the missing classes in the jar itself or add those to the system classpath.

Eclipse don't recognize test folder as source folder when importing ant build file

I have an ant build file for a java project the project tree looks like this :
DataBaseFidling.
|-->src (contains production code source)
|-->tests (contains tests code source)
|-->bin (contains .class)
|-->reports(contains junit xml reports)
|-->build.xml
Whenever I import this project with eclipse using "Java Project From Existing Ant Build File", eclipse does not reconize the tests folder as a source folder.
What to do to fix this?
Here is the ant build file :
The DatabaseFidling Project.
<property name="src.dir" location="./src/" />
<property name="tests.dir" location="./tests/" />
<property name="bin.dir" location="./bin/" />
<property name="lib.dir" location="/home/chedy/workspace/lib"/>
<target name="clean">
<delete verbose="true">
<fileset dir="${bin.dir}"/>
</delete>
</target>
<target name="compile">
<javac srcdir="${src.dir}" destdir="${bin.dir}">
</javac>
<javac srcdir="${tests.dir}" destdir="${bin.dir}">
<classpath>
<pathelement location="${lib.dir}/junit4.jar"/>
<pathelement location="${lib.dir}/mockito-all-1.9.5.jar"/>
<pathelement location="${lib.dir}/SQLScriptRunner.jar"/>
</classpath>
</javac>
</target>
<target name="test" depends="compile">
<junit printsummary="yes" fork="true" >
<formatter type="xml"/>
<classpath>
<pathelement path="${bin.dir}"/>
<pathelement location="${lib.dir}/junit4.jar"/>
<pathelement location="${lib.dir}/mockito-all-1.9.5.jar"/>
<pathelement location="${lib.dir}/SQLScriptRunner.jar"/>
<pathelement location="${lib.dir}/mysql-connector-java-5.1.23-bin.jar" />
</classpath>
<batchtest todir="./report">
<fileset dir="${bin.dir}">
<include name="**/**Test*.*"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="run" depends="compile">
<java classname="com.esprit.is.Main" fork="true">
<classpath>
<pathelement path="${bin.dir}"/>
<pathelement location="${lib.dir}/mysql-connector-java-5.1.23-bin.jar" />
</classpath>
</java>
</target>
</project>
You can manually add the test folder as a source folder. Right click the project, Build Path -> Configure Build Path -> Java Build Path. In the Source tab, click Link Source then browse to your folder.
The compile target had to contain one javac task which compiles both the src and test folders.

Ant + Junit Issues

I am trying to get Junit work with Ant. I have come across questions on the topic. I guess there is some small error somewhere but I can't figure it out. Here is my Build file:
<?xml version="1.0" encoding="UTF-8"?>
<project name="IvleFileSync" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<!-- Variables used for JUnit testing -->
<property name="test.dir" location="test" />
<property name="test.report.dir" location="test-reports" />
<path id="junit-classpath">
<fileset dir="${test.dir}">
<include name = "*" />
</fileset>
</path>
<path id="files-classpath">
<fileset dir="/usr/lib" >
<include name="*.jar"/>
</fileset>
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
<mkdir dir="${test.report.dir}" />
</target>
<target name="compile" depends="init" description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<path refid="files-classpath" />
</classpath>
</javac>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/IvleFileSync-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="compile-test" depends="compile" description="compile the tests " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${test.dir}" destdir="${build}">
<classpath>
<path refid="files-classpath" />
</classpath>
</javac>
</target>
<target name="test" depends="compile-test" description="Execute Unit Tests" >
<junit printsummary="yes" fork="yes" haltonfailure="yes" showoutput="false">
<classpath >
<path refid="files-classpath" />
<path refid= "junit-classpath" />
</classpath>
<batchtest fork="yes" todir="${test.report.dir}/">
<formatter type="xml"/>
<fileset dir="${test.dir}">
<include name="*Test*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${test.report.dir}" />
<delete dir="${dist}"/>
</target>
</project>
And I have test files in /test directory as well as i have put the jars in ANT_HOME/lib
That does not work and I get this error when I dig up the test-results/....xml
<error message="NewEmptyJUnitTest" type="java.lang.ClassNotFoundException">java.lang.ClassNotFoundException: NewEmptyJUnitTest
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
Thanks for helping me out...
The classpath for the junit task does not include the output of the compile-test target. Use something like the following for the JUnit classpath:
<classpath>
<pathelement path="${build}"/>
<path refid="files-classpath" />
<path refid="junit-classpath" />
</classpath>
You forgot to add your own classes ("build") to the "test" target.

Can't run leJOS NXJ sample project

I try to install leJOS NXJ on my MAC OS X and run it's sample, but after I do what it wants and export NXJ_Home Path file and etc. and install netbeans plugin and create it sample project (Creating your own project using the Netbeans Plugin). I also follow this structure and replace desire classes.jar from intsall leJOS NXJ installation's lib folder.
I export these 4 lines:
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$
This is leJOS NXJ sample code:
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();
}
}
and this is related build.xml file:
<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>
and this is 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>
I get this error:
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/
a little bit late but may other like me are looking for a solution. I am new on leJOS and Netbeans and Java (starting tonight).
My environment is WindowsXP with Netbeans 6.9.1.
leJOS is installed in C:/Programme/leJOS NXJ
First Project: HelloWorld
I fixed it by setting the nxj.home var in the build.properties file laying in the project root directory (here /HelloWorld/ and build.xml is also there).
The nxj.home has to point to the leJOS installation path. In my case:
nxj.home=C:/Programme/leJOS NXJ
Hope it helps
Joe.

Categories