Using an ANT file to upload and run your project directly

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

Moderators: roger, gloomyandy, skoehler

Using an ANT file to upload and run your project directly

Postby esmetaman » Sat Sep 28, 2013 11:29 am

Hi mates,

I share an example to use an ANT file (build.xml) to upload and run your development with your EV3 brick.

Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="Brity" default="run" basedir=".">
   <description>
Ant file designed to upload and run a EV3 project using LeJOS project.
   </description>
   
   <!-- DEVELOPMENT SECTION -->
   <property name="project" value="Brity"/>
   <property name="version" value="0.1"/>
   <property name="base.dir" value="." />
   <property name="src" location="src"/>
   <property name="lib" location="${base.dir}/lib" />
   <property name="logs" location="${base.dir}/logs" />
   <property name="build" location="build"/>
   <property name="dist"  location="target"/>
   <property name="dist.lib"  location="${dist}/lib"/>

   <!-- EV3 SSH SECTION -->
   <property name="host" value="192.168.43.62"/>
   <property name="username" value="root"/>
   <property name="password" value=""/>
   
   <!-- EV3 LINUX SECTION -->
   <property name="remotePath" value="/home/root/lejos/examples/"/>

   <!-- CLASS SECTION -->
   <!--
   <property name="package" value="jab.lejos.liverobots.brity.states"/>
   <property name="class" value="Observe"/>
   <property name="package" value="jab.lejos.db"/>
   <property name="class" value="TestDB"/>   
   -->
   <property name="package" value="jab.lejos.utils"/>
   <property name="class" value="log4jExample"/>

   <!-- TARGET SECTION -->
   <target name="init">
      <antcall target="local-init" />
      <antcall target="remote-init" />
   </target>
   
   <target name="local-init" description="Initializating local environment" >
      <tstamp/>
      <echo message="Initializating local environment."/>
      <mkdir dir="${build}"/>
      <mkdir dir="${logs}"/>
      <mkdir dir="${dist}"/>
      <mkdir dir="${dist.lib}"/>
   </target>

   <target name="remote-init" description="Initializating local environment" >
      <tstamp/>
      <echo message="Initializating remote environment."/>
      <sshexec host="${host}"
         username="${username}"
         password="${password}"
         command="cd ${remotePath}; rm -f -r ${project}; mkdir ${project}; cd ${project}; mkdir lib;"
      />
   </target>
   
   <target name="compile" depends="init" description="Compile your project" >
      <tstamp/>
      <echo message="Compiling project."/>
      <javac srcdir="${src}" destdir="${build}">
         <classpath>
            <fileset dir="${lib}">
                    <include name="**/*.jar" />
            </fileset>
         </classpath>
      </javac>
   </target>
      
   <target name="dist" depends="compile" description="generate the distribution" >
      <tstamp/>
      <echo message="Packaging project."/>
      <jar jarfile="${dist}/${project}-${DSTAMP}.jar" basedir="${build}">
            <manifest>
          <attribute name="Built-By" value="${user.name}"/>
            <attribute name="Specification-Title" value="${project}"/>
            <attribute name="Specification-Version" value="${version}"/>
            <attribute name="Specification-Vendor" value="JAB"/>
            <attribute name="Implementation-Version" value="${version} ${TODAY}"/>
            <attribute name="Implementation-Vendor" value="JAB"/>
               
             <attribute name="Main-Class" value="${package}.${class}"/>
            <attribute name="Class-Path" value="lib/log4j-1.2.17.jar lib/hsqldb.jar"/>
            </manifest>
      </jar>
      <echo message="Packaging project dependencies."/>
      <copy file="${lib}/log4j.properties" toDir="${dist.lib}"/>
      <copy file="${lib}/log4j-1.2.17.jar" toDir="${dist.lib}"/>
      <copy file="${lib}/hsqldb.jar" toDir="${dist.lib}"/>
   </target>

   <target name="upload" depends="dist">
      <tstamp/>
      <echo message="Deploying software into EV3 Brick."/>
       <scp file="${dist}/${project}-${DSTAMP}.jar"
            todir="${username}:@${host}:${remotePath}${project}/"
      />
      <echo message="Deploying software dependencies into EV3 Brick."/>
      <scp todir="${username}:@${host}:${remotePath}${project}/lib/">
         <fileset dir="${dist.lib}"/>
      </scp>
   </target>
   
   <target name="run" depends="upload">
      <tstamp/>
      <echo message="Running software."/>
      <sshexec host="${host}"
         username="${username}"
         password="${password}"
         command="cd ${remotePath}${project}/; jrun -jar ${project}-${DSTAMP}.jar "
      />
      <antcall target="clean" />
      
   </target>

   <target name="clean" description="clean up" >
      <delete dir="${build}"/>
      <delete dir="${dist}"/>
   </target>
</project>




With this example, you will save some time because, if you know the place where your project will be located, only you will have to develop and test your software for your EV3 robot.

Cheers
Last edited by esmetaman on Wed Oct 02, 2013 6:29 pm, edited 1 time in total.
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Using an ANT file to upload and run your project directl

Postby lawrie » Mon Sep 30, 2013 8:22 am

This is very similar to the ant build file used by the leJOS menu which is now in the EV3Menu project in git.

However, you seem to be creating a runnable jar file and then executing it as a non-runnable jar file. The menu will require runnable jar files in /home/lejos/programs.

To make it a runnable jar file you need to include the classpath in the manifest and execute it by jrun -jar <jarfile>

Do you have third party libraries installed to allow you to access the scp and sshexec tasks?

Lawrie
lawrie
leJOS Team Member
 
Posts: 840
Joined: Mon Feb 05, 2007 1:27 pm

Re: Using an ANT file to upload and run your project directl

Postby esmetaman » Mon Sep 30, 2013 7:53 pm

Hi Lawrie,

I didn't know it, but I will take a look. This week, I will try to update it with more features and I will check manifest section.

Yes, I am using third party libraries as Joda-Time, Log4j and HSQLDB at the moment.

The attribute -cp is great! in NXT we didn't have that feature, EV3 with LeJOS is nice!
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Using an ANT file to upload and run your project directl

Postby lawrie » Tue Oct 01, 2013 12:05 pm

I meant third party libraries for the ant task. I don't believe scp and sshexec are built-in ant tasks. I am using jsch for the scp task. I don't use sshexec
lawrie
leJOS Team Member
 
Posts: 840
Joined: Mon Feb 05, 2007 1:27 pm

Re: Using an ANT file to upload and run your project directl

Postby esmetaman » Wed Oct 02, 2013 6:32 pm

Hi Lawrie,

many thanks for the notes and example:
http://sourceforge.net/p/lejos/ev3/ci/m ... /build.xml

I have just updated ANT file.

Latest version here:
https://github.com/jabrena/liverobots/b ... /build.xml

Cheers
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Using an ANT file to upload and run your project directl

Postby skoehler » Wed Oct 02, 2013 7:03 pm

esmetaman wrote:The attribute -cp is great! in NXT we didn't have that feature

Whaaaat? Of course nxjlink has a -cp command line parameter.
skoehler
leJOS Team Member
 
Posts: 1350
Joined: Thu Oct 30, 2008 4:54 pm

Re: Using an ANT file to upload and run your project directl

Postby esmetaman » Wed Oct 02, 2013 7:19 pm

Hi,

I didn't know that feature. :)
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://www.roboticaenlaescuela.es
User avatar
esmetaman
Advanced Member
 
Posts: 236
Joined: Wed Sep 13, 2006 12:16 am
Location: Madrid, Spain

Re: Using an ANT file to upload and run your project directl

Postby brickinthecloud » Sun Nov 10, 2013 8:24 pm

Awesome work with the Ant script, saved me likely hours of downloading the referenced components from the current note. Standard Java project, Ant script and one external lib download and thats it! Nice!
brickinthecloud
New User
 
Posts: 21
Joined: Thu Nov 07, 2013 1:56 am


Return to EV3 Software

Who is online

Users browsing this forum: fuzzycow and 3 guests

more stuff