Codename One and third party libraries best practices

768 views
Skip to first unread message

pawel.wic...@gmail.com

unread,
Jan 5, 2014, 2:54:24 PM1/5/14
to codenameone...@googlegroups.com
Hi,
I am totally new to Codename One and recently got involved in Codename One project. I want to ask some questions related to best practices when we want to use some third party libraries with Codename One. First I want to describe what we already have in our project to clarify my doubts. 
We are using two libraries: bouncy castle and protostuff. We have external eclipse project for that libraries with downloaded sources and with added lib CLDC11.jar . Now I want to ask some questions as I'll be describing how we got this to work. 
So first we have to build this project in eclipse. And here are my doubts about this step:
1. Is this ok to compile java sources outside of Codename One project and then use it (so they are not compiled via ant script in Codename One project and are just copied into application jar)? Only thing I've changed in this step was setting compliance  level to java 1.5 and changed code so it could be compiled.
2. Those libraries have some dependencies to core java classes  that are missing in CLDC11.jar from e.g. java.io or java.security package. So we have some core java sources in same project. When I tried to send build I got some errors so I've changed names of those java packages to resolve conflicts. So my question is: is it ok to use core java classes this way?
Next step is to include those classes in Codename One build. So we did it by editing build.xml file and changed some classpath and adding some fileset on copy libs target. So te question is: is it good practice to change build.xml file this way? 

Now if it is totally messed up what solution do You suggest? 
For bouncy castle I know there already are compiled binary for Codename One. So I will try them. One thing that I already saw is that there are some missing classes when comparing orginal bouncy castle with codename one bouncy caste sources. I hope this will not be big problem.
For protostuff I came up with two solutions:
1. Create Codename One library project for them. But as I mentioned before they are using some core java classes that are missing in Codename One so question how to deal with it?
2. Remove protostuff. We are using it for object to json conversions but it can be done with core Codename One classes.

So before I start to reorganize this whole project I wanted to be sure that I am doing and getting this correctly.

Best regards.

Eric Coolman

unread,
Jan 5, 2014, 3:22:30 PM1/5/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
The Bouncy Castle cn1lib is based on the lightweight API for J2ME, so you'll find certain things missing like the JCE implementations, etc.  

For creating a protostuff cn1lib, you should base it on the protostuff-me package rather than the full version.  Go through the prototuff-me and make sure it doesn't import any swing or awk classes, and you'll have a good chance of it working across most platforms.

Eric

Shai Almog

unread,
Jan 6, 2014, 12:48:24 AM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Hi,
1. Not really. You can look in the build.xml file we currently use source/target 1.5 and determine the bootclasspath. Assuming you use javac (not jikes, ADT etc.) this should be fine.
Problem is that things might appear to work for some cases then fail on you later on.

2. If I understand correctly you took java.* packages, copied them to your own packages then changed the sources to point at the com.mycompany package instead of java.*?
That should work fine.

The main issue with pretty much all parsers/generators in the JavaSE/EE world is that they use either reflection or bytecode manipulation both of which are bad ideas for devices (and not great for servers either).

pawel.wic...@gmail.com

unread,
Jan 6, 2014, 4:12:01 AM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Eric, Shai,
Thanks for the clarifications. So i will try Your bouncy castle cn1lib along with protostuff-me as Codename One library.
Thanks a lot!

pawel.wic...@gmail.com

unread,
Jan 6, 2014, 9:24:03 AM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Hi, 
 So Your bouncy castle cn1lib works fine. But I have some questions about creating Codename One library from protostuff.
First I want to higlight some problem I run into (maybe it will help someone):
1. I had to download Netbeans because there is no Codename One Library available on Eclipse
2. I had to use jdk 7  - codename one plugin didn't work with jdk 6
3. I had some problems while generating javadocs ("illegal package name") - I've just skip generating javadoc
4. Strangely I had some compilation errors due to use of assertions (they didn't came up when building with eclipse) - I removed them from code.
5. There was missing native\javase folder - had to create it manually

But the main problem are dependencies: protostuff needs jackson, jackson needs SecureRandom class  SecureRandom class was implemented on top of bouncy castle (which I couldn't add as cn1lib dependency). So I ended up with all sources that I had in orginal project that I described in my first post. I hoped that maybe cn1lib will be included with application jar instead of java classes. Unfortunatly it is not true. So again my android build works just fine and builds on other platforms ends up with memory problems (see my other post here)
Can You suggest any solution to this?
Here are some my thoughts:
Should I implement SecureRandom so it will not depend on bouncy castle?
Should I give up on protostuff and use something simpler?
Maybe upgrade to pro account will give us access to more memory?

Best regards.

Chen Fishbein

unread,
Jan 6, 2014, 9:55:33 AM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Hi,
What functionality you need from the protostuff? if it's just for "object to json conversions" take a look at 
com.codename1.processing.Result

pawel.wic...@gmail.com

unread,
Jan 6, 2014, 11:06:04 AM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Hi,
Yes it is only for "object to json conversions" right now. As far as I know when using com.codename1.processing.Result i need to manualy parse all objects? It is one time work so it is not that bad I think. And I looked at protostuff-me and we use it in our project but we also have some additional files from  protostuff-json that generates those dependencies to jackson. 

Eric Coolman

unread,
Jan 6, 2014, 1:53:12 PM1/6/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
The schema evolution and automatic data binding features of protostuff are appealing to me.  I'd be interested in contributing to a public protostuff cn1lib.

I took a quick peek at protostuff-json, and it looks like they are using a relatively small set of functionality from Jackson.  The combination of com.codename1.processing.Result and com.codename1.processing.PrettyPrinter (currently not public, it's used by Result.toString() to write the dom to JSON) could probably be adapted for data binding in place of Jackson.

Eric

pawel.wic...@gmail.com

unread,
Jan 12, 2014, 3:06:38 AM1/12/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
Eric,
It would be awesome to have protostuff as cn1lib. I assume that there is no point for trying to get rid off jackson from protostuff right now since PrettyPrinter  is not public? What do You suggest? What should be next step do get this done?

Best regards.

Eric Coolman

unread,
Jan 12, 2014, 1:11:50 PM1/12/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
I've done some work in porting Protostuff over.  I'm looking at re-implementing the portions of code in protostuff-json that uses Jackson, to remove that dependency.  Will let you know if I have success in that.

Paweł WIchrowski

unread,
Jan 12, 2014, 1:51:40 PM1/12/14
to codenameone...@googlegroups.com, pawel.wic...@gmail.com
That's great!  Really appreciate Your help!
Reply all
Reply to author
Forward
0 new messages