Thursday 6 February 2014

Using ANT on Raspberry Pi

Install the Java Runtime
pi@raspberrypi ~/testProject $ sudo apt-get install openjdk-7-jre
Install the Java Development Kit
pi@raspberrypi ~/testProject $ sudo apt-get install openjdk-7-jdk

Check where Java is installed
pi@raspberrypi ~/testProject $ which java
It was installed in /usr/bin/java on my Pi
Set up the JAVA_HOME environment variable
pi@raspberrypi ~/testProject $ export JAVA_HOME=/usr 
Install ANT
pi@raspberrypi ~/testProject $ sudo apt-get install ant
Make a directory for the Java project
pi@raspberrypi ~/testProject $ mkdir ~/testProject 
Change to the testProject directory
pi@raspberrypi ~/testProject $ cd ~/testProject 
Create a simple Java file Test.java. This just prints a message saying "Test.java is running".
public class Test {
        public static void main(String[] args) {
                System.out.println("Test.java is running");
        }
}

Create an ANT build file, build.xml

        
                
        

There is just one target in the build file to compile the source code. You can run the build file with ant by just running ant
pi@raspberrypi ~/testProject $ ant
After this finishes building, check the contents of the directory for the java class file
pi@raspberrypi ~/testProject $ ls
build.xml Test.class Test.java
Run the Java program
pi@raspberrypi ~/testProject $ java Test
Test.java is running

No comments:

Post a Comment