Library package does not exist

158 views
Skip to first unread message

Raanan Mintz

unread,
Mar 23, 2013, 8:52:13 AM3/23/13
to codenameone...@googlegroups.com
I am re-factoring an app to split off common library classes to be used by other related apps I want to develop. I created a library with NetBeans, and moved the packages of classes from the app to this library. I went to the app's Properties dialog, clicked on Add Project, selected the library project, and clicked on Add Project JAR Files. So far so good. Both the app and the library compile without errors. The import statements in the app for the library classes look OK. The library JAR file seems to contain the right class files. However, when I try to run the app, I get a series of error messages for all of the references to the library.
  • package xxx does not exist (on import statement from the library)
  • cannot find symbol (on instantiating a library class object)
What am I doing wrong?

Shai Almog

unread,
Mar 23, 2013, 9:18:45 AM3/23/13
to codenameone...@googlegroups.com
You can't add a jar to a library project, or at least not like that.
A library project needs to include the source code of the library and potentially the "native" libraries under the native folders.
E.g. if you have an Android native jar and an iOS .a file you can just place them under the appropriate native hierarchy and then use Codename One native interfaces to invoke them.

You cannot add an arbitrary jar to the standard Codename One project since our build process needs the code to be compiled in a very specific way.

Raanan Mintz

unread,
Mar 23, 2013, 9:43:35 AM3/23/13
to codenameone...@googlegroups.com


On Saturday, March 23, 2013 9:18:45 AM UTC-4, Shai Almog wrote:
You can't add a jar to a library project, or at least not like that.

I am not trying to add a JAR to a library project. My library project does contain source code folders (packages).

A library project needs to include the source code of the library and potentially the "native" libraries under the native folders.
E.g. if you have an Android native jar and an iOS .a file you can just place them under the appropriate native hierarchy and then use Codename One native interfaces to invoke them.

You cannot add an arbitrary jar to the standard Codename One project since our build process needs the code to be compiled in a very specific way.
 
Yes, I do want to add the library project source code to my app project. On the Properties dialog there is Sources category. Is that what I should be using. When I try to do that I get an error message. I appreciate your support.

Basically, I want to know how to properly use a NB-CN1 library in an app project.

Shai Almog

unread,
Mar 23, 2013, 11:59:43 AM3/23/13
to codenameone...@googlegroups.com
No. You should build the library then copy the file (you can automate this in the ant script) to the lib directory under your regular project.
You can manually invoke refresh libs (right click on the project) and it will happen automatically when you send a build to the server.

Raanan Mintz

unread,
Mar 23, 2013, 4:19:42 PM3/23/13
to codenameone...@googlegroups.com


On Saturday, March 23, 2013 11:59:43 AM UTC-4, Shai Almog wrote:
No. You should build the library then copy the file (you can automate this in the ant script) to the lib directory under your regular project.
You can manually invoke refresh libs (right click on the project) and it will happen automatically when you send a build to the server.

Thanks. Manually copying the cn1lib file from the "library" to my app worked for running the simulator (have not tried a build yet with the library). Of course, but it is a little awkward to have to remember to copy the file every time I modify anything in the library class .

When you say ant script, I presume you mean the build.xml file? Unfortunately, I have never used ant, it is not obvious to me how to do this.

Is it likely that using a "library project" with NetBeans will become more automatic at some point? Should I add an issue to that effect?

In any case, using a library project "uncouples" my common code from the apps using it, which was my goal. Is there anything I could do to add some of this information to the Users Guide? I am a good technical writer.

Shai Almog

unread,
Mar 23, 2013, 4:22:07 PM3/23/13
to codenameone...@googlegroups.com
No. We won't be able to support the libraries in NetBeans since that is too ingrained in the IDE.
We are thinking about adding a dependency UI but that might take some time.

fromyo...@gmail.com

unread,
May 31, 2014, 11:07:55 AM5/31/14
to codenameone...@googlegroups.com
Hi,
    I need to use java 7, in Android so I created package then created jar, Then I tried to use it with NativeInterface , it seem it is incomplete examples i found in Codename One developer guide and NativeDemo, I tried to run but couldn't...

I need to use the Jar and Build for Android..
in NativeDemo only they included MyNative interface not any other classes in Developer pdf they said MyNativeImol implements MyNative but in NativeDemo there is no souch thing exists..

I love to use Java 7 with Code Name one , I love both, kindly.. where I can have a complete example ?

Shai Almog

unread,
Jun 1, 2014, 2:21:24 AM6/1/14
to codenameone...@googlegroups.com, fromyo...@gmail.com
Hi,
please don't revive unrelated old threads the next time. Just start a new thread.

You can just place other Java sources in the same hierarchy and they will be compiled on the server. The impl class can invoke external classes without a problem.

Reply all
Reply to author
Forward
0 new messages