1

I have an android libary project - MonitoringModel - which depends on a regular java project - Helpers (the dependency was set in the java build path > Projects. The Helpers project was ticked in the "order and export" tab of the MonitoringModel). MonitoringModel produces a jar which I drop to the libs folder of a servlet project as described here. All was fine till the servlet needed a method from the Helpers project :

Caused by: java.lang.NoClassDefFoundError: gr/uoa/di/java/helpers/Utils
 at gr.uoa.di.monitoring.model.Battery$BatteryFields$1.parse(Battery.java:59)
 at gr.uoa.di.monitoring.model.Battery$BatteryFields$1.parse(Battery.java:1)
 at gr.uoa.di.monitoring.model.Battery.parse(Battery.java:117)
 ... 24 more
Caused by: java.lang.ClassNotFoundException: gr.uoa.di.java.helpers.Utils
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)


I realized then that the exported jar (from the MonitoringModel) had not the Helpers packages. The Helpers project does not create any jar so I tried adding its bin/ folder as Add Class Folder)


enter image description here

adding it also in "order and export" tab :

enter image description here

but still no joy.

So how should I set this up ?

RECAP : What I am after is a way to add a regular java project into an android library project and have this compiled in the jar of the android library project somehow. Τhe problem is not so much that the (java) classes are not exported - as that the methods that use those java classes are not compiled in the jar correctly. So when they are called the exception above is thrown. The Battery$BatteryFields$1.parse method is here.

NB : adding the Helpers project directly to the servlets project does not prevent the exception. The exception is thrown because when MonitoringModel.parse() calls Helpers.listToString() the latter is nowhere to be found in monitoringmodel.jar
For the moment I had to simply add (see Copy Paste) the Helpers packages to the MonitoringModel.

Community
  • 1
  • 1
Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361

1 Answers1

0

You have to compile your Helper Java Project independent, and export a JAR like a normal Java JAR

Then, you have to add this JAR to Monitor Android Library LIBS folder.

Now you can add the Monitor Android Library to another project (From Android Libraries box), and it will have the sources that you need.

The problem is that the Project Tab does not compile anymore the referenced project since some ADT Version, so it's useless.

noni
  • 2,927
  • 19
  • 18
  • Thanks for answer but please read more carefully - while I used the projects tab initially I switched to the Libraries tab - and most important : I want to use the MonitoringModel in a NON android project - this is possible as I said in the question (link again) [here](http://stackoverflow.com/a/18594605/281545). I am very interested in this - maybe a post in the android dev group is in order. – Mr_and_Mrs_D Sep 27 '13 at 19:59
  • Also please provide more detailed instructions on jaring the helpers project - preferably some automated way (ant ?). – Mr_and_Mrs_D Sep 27 '13 at 20:00