Procedure to create and compile javaHelloWorld

Configuration:

  • Developer Studio 5.3.1 / Linux
  • WP77 R9 (18.3.0.wp77xx-native-x86_64-201806051023)
  1. Prepare your host

Follow this procedure:
https://source.sierrawireless.com/resources/airprime/software/legato_application_development_kit_linux/
especially the dedicated step:
If you plan to develop Legato applications with Java language

Then:

on host:
sudo get-install ant

  1. Retrieve the embedded JVM

for the test, I used ejdk-8u171-linux-arm-sflt.tar.gz
then
unzip to a local folder on your host PC, in my case in ~/ejdk/

  1. Create the app in dev studio:

In Projects perspective:
File > New > Import existing code as legato project
[Browse]
legato/packages/legato.framework.18.3.0.wp77xx-201806050955/resources/legato/apps/sample/javaHelloWorld/
check box: copy files into workspace
[Next]
Select your target platform, in my case [Built-in] Legato for WP77 R9

  1. Build you app

You have 2 options

  • you can install the JVM on your target and point the app to it >> jump to section 5
  • bundle the JVM in the app >> jump to section 6
  1. JVM on target

Advantage is application binary very small 3.6KB
Multiple java app can rely on the same JVM

5.1  install JVM on target

Copy the host folder ~/ejdk/ejdk1.8.0_171/linux_arm_sflt/compact1 content including subfolder /bin and /lib to the target file system
In my case in target folder /home/root/java

on target
cd ~
mkdir java

on host
cd ~/ejdk/ejdk1.8.0_171/linux_arm_sflt/compact1
scp -r ./* root@192.168.2.2:/home/root/java

5.2 configure the project

Right click on project > Properties > C/C++ Build > Environment > environment variables to set > [Add…]
Name: EJDK_DIR
Value: /home/root/java >> need to match the target folder defined in 4.1
Check: Add to all configurations
[OK]
[Apply and Close]

5.3 edit component.cdef

need to specify onTargetOracleJvm:

requires: {
    component: {
        onTargetOracleJvm
    }
5.4 Build and run

Click on the build and install icon (green arrow)
If everything went well, you should see the following target log message:

Jan 6 18:00:27 | UNKNOWN[21559]/javaHelloWorld T=main | io.legato.samples.javaHelloWorldComponent componentInit() 8 | Hello, World (from Java).

  1. Bundle the JVM in the app itself

Much bigger app since it also include the JVM. (12MB vs 3.6KB!)
Multiple java app will all have to embed their own JVM
Advantage: we are sure about which JVM version we run

6.1 configure the project

Right click on project > Properties > C/C++ Build > Environment > environment variables to set > [Add…]
Name: EJDK_DIR
Value: /home/bbo/ejdk/ejdk1.8.0_171/linux_arm_sflt/compact1 >> need to match the host location where you unzip the JVM
Check: Add to all configurations
[OK]
[Apply and Close]

6.2 edit component.cdef

need to specify embeddedOracleJvm

requires: {
    component: {
        embeddedOracleJvm 
    }
6.3 Build and run

Click on the build and install icon (green arrow)
If everything went well, you should see the following target log message:

Jan 6 18:00:27 | UNKNOWN[21559]/javaHelloWorld T=main | io.legato.samples.javaHelloWorldComponent componentInit() 8 | Hello, World (from Java).

HI BBO,
thanks for this topic!

No problem!
I struggled a bit to gather all the details from various sources with @jyijyi, I thought it would be a waste not to share!

thanks a lot!!

I wish there is more information on how to develop apps with Java on Legato!!
=) , could you please share some if you have it! =)

Thanks

Hello

Why use Java to develop apps ?

Francis

hello @FrancisDuhaut

Simple reasons I can think about can be skills, existing java code re-use for a migration project or for portability across various platform…

1 Like

I understand but performance will be reduced ??
Java code is compiled or interpreted ?

I’m curious.
Thanks
Francis