Resolving imports for java.nio.ByteBuffer, java.util.Formatter


#1

I am having some trouble importing some of the libraries.

For example, I can see in the MicroEJ documentation, that java.util.Formatter should be supported: https://developer.microej.com/javadoc/microej_4.1/addons/java/util/Formatter.html

But when I try to import java.util.Formatter in my project, I get an error saying that the import cannot be resolved. I am guessing this is maybe a configuration issue with my project?

I see a similar issue when I try to import java.nio.ByteBuffer. I can see it documented here:
https://developer.microej.com/javadoc/microej_4.1/addons/java/nio/ByteBuffer.html#ByteBuffer--

But I get an error “The import java.nio cannot be resolved” when I try to import it. Do you have any ideas how I can resolve? Thanks!


#2

Hi David,

The MicroEJ Java libraries are split in two types (see http://developer.microej.com/#APIs):

  • Foundation Libraries: implementation is specific to the platform ; depends on C ; built-in in the MicroEJ Architectures
  • Add-on Libraries: full java implementation ; available on the MicroEJ Central Repository (ivy repository)

The ByteBuffer and Formatter classes are both available in add-on libraries. You can use it either by adding manually the Jars in your project classpath configuration or using Ivy dependency manager.
Ivy manages automatically the transitive dependencies of a library. You can find here a simple example that uses Ivy to retrieve logging library: https://github.com/MicroEJ/Example-Standalone-Eclasspath/tree/master/com.microej.examples.eclasspath.logging . The dependencies are declared in the module.ivy file.

The Formatter library that includes the Formatter class is available here: http://developer.microej.com/4.1/ivy/artifacts/ej/library/eclasspath/formatter/2.0.0/
The ByteBuffer library that includes the ByteBuffer class is available here: http://developer.microej.com/4.1/ivy/artifacts/ej/library/eclasspath/bytebuffer/1.0.1/

Most of the typical J2SE classes are available in these libraries: http://developer.microej.com/4.1/ivy/artifacts/ej/library/eclasspath/

You can find here a list of all the add-on libraries classes: http://developer.microej.com/javadoc/microej_4.1/addons/index.html
And here a list of all the foundation libraries classes: http://developer.microej.com/javadoc/microej_4.1/foundation/index.html

More information here:

Jerome


#3

I am receiving this same issue with ByteBuffer. The rest of my libraries are recognized, but when SOAR attempts to link I get the following message:

Class ‘java.nio.ByteBuffer’ is referenced, but cannot be loaded: 'VERIFIED_REJECTED

I checked several of the examples, but I don’t see an issue. This project builds fine in the SDK, but I run into this when trying to build from the command line.


#4

Did you add this library to your classpath (using ivy or project configuration) ?
http://developer.microej.com/4.1/ivy/artifacts/ej/library/eclasspath/bytebuffer/1.0.1/


#5

Yes I did. In the -ivy-provisioning:resolve: section of running the build script it finds all the libraries, also everything appears to compile correctly. It’s when it gets to the point of linking that it can’t seem to find them.