External Java libraries


#1

Hi,
I am trying to use external Java libraries for a mangOH green in my Legato Java application. I use Developer Studio 5.0 and the “JavaHelloWorld” sample works fine. I added the libraries I want to use in the project properties under “Java Build Path”. Also I include them at the “Component.cdef” file with “bundles: {file: { … } } “. But every time I get the error: “package does not exist”.


#2

Hi @tli

This is a known limitation.
You’re doing the things the right way, but for now the class path used at compilation time and at runtime doesn’t take bundled jar files into account.
We’re starting a rework task concerning Java for Legato here, and this will be fixed in next major Legato release (should be released at some time in June 2017)


#3

Hi, @daav!
I’m very intrested in using java with external libraries on my mangoh + wp8548 module, but it seems that there was no update of legato AF since that theme was started.
Is that true, or i can install anything newer than 16.10.3 (source)
Regards!


#4

Hi @kent1ukr

Java updates have been implemented among successive versions since 16.10.3, but it’s true that this one it still the latest official package for WP85 (please refer to http://legato.io/legato-docs/latest/aboutReleaseInfo.html for more information on how hardware package releases are scheduled WRT. the master monthly releases)

That said, you still can build the Framework by your own, at the version you want, and get it into DS so that you can build apps on top of it (Instructions here: Adding newest version Legato Framework into Developer Studio)


#5

Hi again @daav
I have recently tryed to build LF by my own, but i have an issue
First of all I followed an instruction [here](https://github.com/legatoproject/legato-af Install required packages)
I downloaded and installed latest toolchain 64-bit SWI9X15Y_07.12.09.00 on WP85
Cloned repo legato-af from GitHub
Compiled make and make wp85. Got compiled folder …/legato/build/wp85
Added in developer studio compiled framework according to instruction
Regards!

And now after creating new Legato Application I have no legato.jar and get en exception "SPN_HOME…/legato/build/wp85/framework/lib/legato.jar (missing)."
And I have onli ‘.so’ files in my lib folder.

I just can’t realize what am I doing wrong. Please help me if you have any suggestions


#6

Hi @kent1ukr,
I’m afraid this is not documented anywhere, but in order to get Java support built when you’re building your own Framework, you need:

  • to be sure that you have a JDK installed on your machine (check that javac command is running OK; minimum version: Java 8)
  • to set the following env vars before building the framework (make wp85):
    export JAVA_INCLUDE_DIR=/usr/lib/jvm/java-8-openjdk-amd64/
    export JDK_INCLUDE_DIR=/usr/lib/jvm/java-8-openjdk-amd64/include

Then, you should get the legato.jar built.


#7

@daav, I have just did what you wrote.
I do have JDK
I exported both passes
but it’s still soesn’t compile LF for me :frowning:
Can it be because off I don’t use latest toolchain (latest available toolchain for me according this page is SWI9X15Y_07.12.09.00 )
thanks for your quick responces


#8

Did you verify if legato.jar is built on the file system after a make wp85?
Maybe you need to do a make clean before trying a new build…

That said, please note that on DS side, you’ll probably need to import again the package (from the Available Packages view), because some metadata are cached at this time (notably if the framework provides a legato.jar or not…)


#9

@daav I tryed too do a make claen and i have eve tryed too delete old wp85 folder before making make85 but it still did not helped at all… I still don’t have .jar file in my lib folder


#10

Please note that the export settings above must be:

  • either done manually each time you open a new shell
  • or added to your .bashrc profile

If you do a ls $JDK_INCLUDE_DIR before the Legato build, is it showing up the content of /usr/lib/jvm/java-8-openjdk-amd64/include?

EDIT: only JDK_INCLUDE_DIR var is mandatory (I edited my previous post).
Just gave a try on a fresh 17.09 repo clone.

$ export JDK_INCLUDE_DIR=/usr/lib/jvm/java-8-openjdk-amd64/include
$ ls $JDK_INCLUDE_DIR 
classfile_constants.h  jawt.h  jdwpTransport.h  jni.h  jvmticmlr.h  jvmti.h  linux
$ make
<snipped output>
$ . bin/configlegatoenv
$ make wp85
<snipped output>
$ find -name *.jar
./3rdParty/pjsip/pjsip-apps/src/pjsua/android/gradle/wrapper/gradle-wrapper.jar
./3rdParty/pjsip/pjsip-apps/src/swig/java/android/gradle/wrapper/gradle-wrapper.jar
./3rdParty/Lwm2mCore/doc/plantuml/plantuml.jar
./3rdParty/plantuml/plantuml.jar
./3rdParty/plantuml/plantuml-8049.jar
./build/wp85/system/staging/lib/legato.jar
./build/wp85/framework/lib/legato.jar
./build/wp85/_staging_system.wp85.update/system/lib/legato.jar
./build/localhost/system/staging/lib/legato.jar
./build/localhost/framework/lib/legato.jar

#11

That was the main thing in my case. Thanks a lot about that!!!

Despite this I still can’t configure my project properly to use external java libraries.
I added extrnal library like I used to do it in eclipse (like here) but when I try to build my project it still doesn’t see that library ( package does not exist ).
So it seems that I’m still there were I started a week ago, but now I have 17.09.0 LF in DS.
Thanks again for your answers.


#12

Hi @daav.
I also have issues with using external jar on my Legato java project.
I’m using mangOH Green with wp8548. According to your recommendations, I updated framework to version 17.09.0 and added it to the DS. Despite this, I also get errors( package does not exist ).
Could you please explain how to properly add and use external jars. In the official documentation (http://legato.io/legato-docs), I did not find any instructions on this case.
Thanks for the answer.


#13

Hi,

unfortunately there is no workaround at the moment.
But yes, this is a blocking point… We’re currently investigating on how we could get this fixed in a future version.