This section contains steps to run Java* Internet of Things applications on an Intel® Edison board or Intel® Galileo board outside of the Intel® System Studio IoT Edition.
Building Java* IoT applications
You can run Java IoT applications outside of the Intel System Studio IoT Edition by manually compiling the code using javac. For compilation, you need the .jar files corresponding to the MRAA* and UPM* libraries on the device. An archive with the latest stable libraries can be found in iotdk-java-latest.zip (the development versions of the UPM and MRAA .jar files can be found here. In the commands below, the following locations and names are used:
- PATH_TO_JARS represents the location where the archive with the .jar files has been unpacked.
- PATH_TO_SOURCE_FILES represents the path to the Java source files.
- bin/ is the directory where the compiled Java classes are placed.
- NAME_OF_JAR_FILE is the name given to the .jar file where the compiled Java classes are placed.
- NAME_OF_MAIN_CLASS is the name of the class that contains the main() method, which is the entry point of the application.
1. Use the following commands to compile and pack the Java files of the IoT Java application:
javac -cp PATH_TO_JARS -d bin/ PATH_TO_SOURCE_FILES
jar cvf NAME_OF_JAR_FILE -C bin/ .
2. Copy the resulting application .jar file (NAME_OF_JAR_FILE) to your Intel® Edison or Intel® Galileo board. On a system with Linux* or OS® X, you can use scp. On a system with Windows*, you can use WinSCP.
For example, assuming your application is in a Sample.java source file placed in C:\workspace\sample\src\(PATH_TO_SOURCE_FILES) and the IoTDK .jar files are in C:\upm (PATH_TO_JARS):
3. Copy the files to the board using scp for Linux or OS X, or WinSCP for Windows:
Running Java IoT applications on IoT devices
In the IoTDK device images, the .jar files needed on runtime for using MRAA and UPM are located in/usr/lib/java. The Java shared libraries are located in /usr/lib, the default path for shared libraries on Linux systems. Therefore, setting the java.library.path with the “-Djava.library.path=/usr/lib” parameter is not necessary.
1. To run your Java application on the target device with the MRAA and UPM libraries, use the following command:
java -cp .:/usr/lib/java/*:NAME_OF_JAR_FILE NAME_OF_MAIN_CLASS
In the example application below, you you would type:
java -cp .:/usr/lib/java/*:sample.jar Sample
2. Connect to the board using ssh or PuTTY and run your application. In the sample application above, you would run the Sample class in the sample.jar file. You can view the output in your terminal window, as shown below:
For more such intel IoT resources and tools from Intel, please visit the Intel® Developer Zone
Other Popular Deals
- The 10 best job hunting apps on AndroidTop 10 Android launchers (June 2017)
- The 10 scariest horror games on AndroidAndroid app stores: 5 best alternatives to Google Play Store
- Best Android apps for rooted devices18 apps for a memorable Valentine's Day
- Top 15 Android games that you should playThe 20 best looking games for mobile phones
- 8 Android apps to tickle your funny bone17 must have apps for any Android device (plus alternatives)
- 5 apps to get the Android Lollipop look on your smartphoneTake control of your Android device with these apps
- 7 weird and strange apps for your Smartphone10 neat Google apps you may not know of
- Perfect Viewer10 essential Indian apps for Android devices