问题
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)
adding it also in "order and export" tab :
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
.
回答1:
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.
来源:https://stackoverflow.com/questions/18981837/android-library-project-does-not-compile-its-java-project-dependencies-into-it