Ant compiled program has uncought exception

This is where you talk about the EV3 software itself, installation issues, and programming talk.

Moderators: roger, gloomyandy, skoehler

Ant compiled program has uncought exception

Postby dlm4ev3 » Sat Jul 05, 2014 8:15 am

When I build a simple HelloWorld type program in Eclipse it compiles, is uploaded, and runs fine on the EV3 brick.

If I take the same source file and compile it using Ant it compiles but the compiled class size is smaller than the Eclipse compiled class size and if a create a Jar file, upload it to the brick using ev3control and the run the program I get an

UNCAUGHT EXCEPTION
java.lang.ClassNotFoundException
null

I have tried to find a build.xml in the lejos distribution that will show me what I am doing wrong but have been unsuccessful. My build.xml file to compile and create the jar file is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="SizeDiff" default="makeJar">
<property name="main-class" value="${ant.project.name}" />
<property name="jar" value="${ant.project.name}.jar" />
<!-- Upload parameters -->
<property name="ev3.ipaddr" value="10.0.1.1" />
<property name="ev3.user" value="root" />
<property name="ev3.password" value="" />
<!-- Class path -->
<property name="lib.dir" value="/home/lejos1/EV3/lejos/lib" />
<property name="ev3class.path" value="${lib.dir}/ev3" />
<!-- Source, class, and jar files here -->
<property name="srcDir" value="." />
<property name="build" value="." />
<property name="jarDir" value="." />

<!-- COMPILE SOURCE =============================== -->
<path id="compile.classpath">
<fileset dir="${ev3class.path}">
<include name="**/*.jar" />
</fileset>
</path>

<target name="init">
<!-- Create the time stamp -->
<tstamp />
<mkdir dir="${build}" />
</target>

<target name="compile" depends="init" description="compile source">
<!-- Compile the java code from ${srcDir} into ${build} -->
<javac srcdir="${srcDir}" destdir="${build}" includeantruntime="false">
<classpath refid="compile.classpath" />
</javac>
</target>

<target name="makeJar" depends="compile" description="Create jar">
<mkdir dir="${jarDir}" />
<jar jarfile="${jarDir}/${jar}" includes="*.class" basedir="${build}">
<fileset dir="${srcDir}" excludes="**/*"/>
</jar>
</target>

</project>

Note that if I use linux make to compile I get the same smaller class file.

The JDK I am currently using is 1.6.0_21 which is also what Eclipse seems to be using.

Any suggestions on how to resolve the Ant compile problem will be appreciated.
dlm4ev3
New User
 
Posts: 4
Joined: Sat Jul 05, 2014 7:49 am

Re: Ant compiled program has uncought exception

Postby epascual » Sat Jul 05, 2014 4:08 pm

Hi,

If you can read French, here is an article I wrote some months ago for controlling the build chain (including remote run) using Ant scripts : http://www.pobot.org/Premier-programme- ... r-EV3.html

I prefer Ant based projects since I'm not found of click-based procedures even when working in Eclipse ;)

BTW working with an Ant toolchain makes possible to use lightweight workstations based on RaspberryPi and Geany for workshops I animate for teaching robot programming to college teachers. It's far easier and faster to clone 15 SD cards than to try to install 15 different PCs collected from here and there ;)

If you are interested, drop me an MP and I can send you the build.xml file I use.

Hope this helps.
Eric PASCUAL - POBOT association VP & co-founder - http://www.pobot.org
epascual
Active User
 
Posts: 123
Joined: Sun Jan 17, 2010 12:15 am
Location: Sophia-Antipolis (France)

FOUND MAJOR PART OF THE PROBLEM

Postby dlm4ev3 » Sun Jul 06, 2014 2:34 pm

JAR FILES CREATED FROM REVISED ANT BUILD.XML EXECUTE ON BRICK

I looked at the contents of the MANIFEST.MF file generated by the lejos plugin to Eclipse. The classpath that they include in their manifest is

Manifest-Version: 1.0^M
Class-Path: /home/root/lejos/lib/ev3classes.jar /home/root/lejos/lib/d^M
busjava.jar /home/root/lejos/libjna/usr/share/java/jna.jar^M
Main-Class: SizeCheck^M
^M

This was not the manifest that my original build.xml generated. I modified the build.xml to duplicate this manifest and the resulting Jar file now executes on the EV3.

MINOR PROBLEM REMAINS
------------------------------
I still do not know why my compiled class file is about 200 bytes smaller than the Eclipse compiled class file. Evidently Eclipse uses a javac argument that is the cause of the difference but I do not know what it is.

----------------------------------------
REVISED BUILD.XML
--------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="SizeCheck" default="makeJar">
<property name="main-class" value="${ant.project.name}" />
<property name="jar" value="${ant.project.name}.jar" />
<!-- Upload parameters -->
<property name="ev3.ipaddr" value="10.0.1.1" />
<property name="ev3.user" value="root" />
<property name="ev3.password" value="" />
<!-- Class path -->
<property name="lib.dir" value="/home/lejos1/EV3/lejos/lib" />
<property name="ev3class.path" value="${lib.dir}/ev3" />
<!-- Source, class, and jar files here -->
<property name="srcDir" value="." />
<property name="binDir" value="." />
<property name="jarDir" value="." />

<!-- CREATE MANIFEST CLASSPATH =================== -->
<property name="ev3Root" value="/home/root/lejos"/>
<property name="ev3Clas" value="${ev3Root}/lib/ev3classes.jar"/>
<property name="ev3Dbus" value="${ev3Root}/lib/dbusjava.jar"/>
<property name="ev3Java" value="${ev3Root}/libjna/usr/share/java/jna.jar"/>
<property name="ev3Path" value="${ev3Clas} ${ev3Dbus} ${ev3Java}"/>

<!-- INITIALIZE =================================== -->
<target name="init" description="INITIALIZE">
<tstamp />
<delete>
<fileset dir="${binDir}" includes="**/*.class **/*.jar" />
</delete>
</target>

<!-- COMPILE ====================================== -->
<path id="compile.classpath">
<fileset dir="${ev3class.path}">
<include name="**/*.jar" />
</fileset>
</path>

<target name="compile" depends="init" description="COMPILE">
<javac srcdir="${srcDir}" destdir="${binDir}" includeantruntime="false">
<classpath refid="compile.classpath"/>
</javac>
</target>

<!-- BUILD JAR ==================================== -->
<target name="makeJar" depends="compile" description="BUILD JAR">
<jar destfile="${jarDir}/${jar}" basedir="${binDir}"
includes="*.class" filesonly="true">
<manifest>
<attribute name="Class-Path" value="${ev3Path}"/>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>

</project>
dlm4ev3
New User
 
Posts: 4
Joined: Sat Jul 05, 2014 7:49 am

Re: Ant compiled program has uncought exception

Postby gloomyandy » Sun Jul 06, 2014 7:40 pm

The difference may not be in code but in meta data, also the eclipse built version may have been compiled using the built in eclipse compiler rather than javac. Personally I wouldn't worry about it!
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4083
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK


Return to EV3 Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff