# Procedure to create and compile javaHelloWorld

**URL:** <https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387>\
**Category:** Legato Application Framework\
**Created:** [June 29, 2018, 7:16am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387 "2018-06-29T07:16:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/bbo/32/489_2.png) [@bbo](https://forum.legato.io/u/bbo)\
**Post date:** [June 29, 2018, 7:16am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/1 "2018-06-29T07:16:42Z")

</div>

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/](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

> **[Java SE Embedded - Downloads | Oracle Technology Network | Oracle](https://www.oracle.com/java/technologies/javase-embedded-downloads.html)**
>
> Downloads for Oracle Java Standard Edition Embedded (Oracle Java SE Embedded).

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)**.

---

<div class="post-metadata">

**Author:** ![plu](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@plu](https://forum.legato.io/u/plu)\
**Post date:** [July 3, 2018, 9:00am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/2 "2018-07-03T09:00:30Z")

</div>

HI BBO,  
thanks for this topic!

---

<div class="post-metadata">

**Author:** ![bbo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/bbo/32/489_2.png) [@bbo](https://forum.legato.io/u/bbo)\
**Post date:** [July 3, 2018, 10:59am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/3 "2018-07-03T10:59:29Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![amil13](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/amil13/32/461_2.png) [@amil13](https://forum.legato.io/u/amil13)\
**Post date:** [July 23, 2018, 10:38am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/4 "2018-07-23T10:38:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FrancisDuhaut](https://avatars.discourse-cdn.com/v4/letter/f/f0a364/32.png) [@FrancisDuhaut](https://forum.legato.io/u/FrancisDuhaut)\
**Post date:** [July 25, 2018, 5:45pm UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/5 "2018-07-25T17:45:39Z")

</div>

Hello

Why use Java to develop apps ?

Francis

---

<div class="post-metadata">

**Author:** ![bbo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/bbo/32/489_2.png) [@bbo](https://forum.legato.io/u/bbo)\
**Post date:** [July 27, 2018, 2:22am UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/6 "2018-07-27T02:22:45Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![FrancisDuhaut](https://avatars.discourse-cdn.com/v4/letter/f/f0a364/32.png) [@FrancisDuhaut](https://forum.legato.io/u/FrancisDuhaut)\
**Post date:** [July 27, 2018, 7:24pm UTC](https://forum.legato.io/t/procedure-to-create-and-compile-javahelloworld/3387/7 "2018-07-27T19:24:42Z")

</div>

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

I’m curious.  
Thanks  
Francis
