Can I compile a CN1 library project as a 'normal' JAR?

39 views
Skip to first unread message

sidiabale

unread,
Apr 28, 2015, 6:29:16 AM4/28/15
to codenameone...@googlegroups.com
Hi,
  1. Is it possible to create a regular JAR file from a CN1 library project such that I can use this jar in an unrelated Java project?
  2. If so, what steps must I follow?
  3. Would there be any limitations/constraints introduced to Java project by using this jar?
 
Thanks
 

Shai Almog

unread,
Apr 28, 2015, 12:49:23 PM4/28/15
to codenameone...@googlegroups.com
Hi,
if you use native interfaces those would not be available.
Sure just add another target to the build.xml that packages a jar, the build.xml does most of the work of building the cn1lib and building a jar is part of that process.

sidiabale

unread,
Apr 29, 2015, 5:57:07 AM4/29/15
to codenameone...@googlegroups.com
Hi,

I don't use native interfaces. I was able to build the jar based on your suggestion. When I try using it in a Java Project, I get the following error upon attempting to make a network request:

java.lang.IllegalStateException: This method should not be invoked by external code!
[Network Thread] 0:0:0,83 - java.lang.IllegalStateException: This method should not be invoked by external code!
   at com.codename1.ui.util.EventDispatcher$CallbackClass.run(EventDispatcher.java:84)
   at com.codename1.ui.Display.callSerially(Display.java:714)
   at com.codename1.ui.util.EventDispatcher.fireActionEvent(EventDispatcher.java:365)
   at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:287)
   at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)
Exception in thread "Network Thread" java.lang.NullPointerException
   at com.codename1.ui.Display.getResourceAsStream(Display.java:2431)
   at com.codename1.impl.CodenameOneThread.getStack(CodenameOneThread.java:140)
   at com.codename1.impl.CodenameOneThread.handleException(CodenameOneThread.java:187)
   at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:179)

Is this something that can easily be tackled?

Shai Almog

unread,
Apr 29, 2015, 12:14:44 PM4/29/15
to codenameone...@googlegroups.com
Hi,
I assumed your app uses plain Java code without relying on things such as networking which are obviously Codename One specific.
You can use the JavaSE port of Codename One but that means you will need to add that into your unrelated project.

sidiabale

unread,
May 1, 2015, 6:07:50 AM5/1/15
to codenameone...@googlegroups.com
Hi,

It worked; thanks!

PS: I also needed to apply the tricks mentioned here. It's a bit awkward though that I must include a dependency on UI components even if I'm making a non-UI Java application but that's not in anyway a show stopper.
Reply all
Reply to author
Forward
0 new messages