Description

Hello to everybody,

I am facing the following problem:

I am trying to use the java driver within the android SDK and it gets crashed when use it as a precompiled jar (ver. 2.3, ver.2.4, ver.2.5)
whether I use it as-is or after converting it to dex format with dx.

I have tried to use the source code in the project but depends on the MBeanServer component and the java.lang.management package , hence it can't be compiled for dalvik because of their absence. The exception is thrown from the file ObjectId.class where
the MBeanServer is called.

I read in jira.mongodb.org/browse/JAVA-170 that the compilation of java.lang.management is optional but I couldn't figure it out.

I see this was planned for 2.6 but was postponed to 2.7, so my question: is there anything I can do, if I want to use mongodb java driver on android?
I'd love to use it instead of building my own server to act as a REST web service broker between android and mongodb...

now when I try to use it it throws:
05-17 15:36:31.390: ERROR/AndroidRuntime(6748): java.lang.NoClassDefFoundError: com.mongodb.Mongo

I've tried downloading the code and to get rid of all references to java.lang.management.* and javax.management.*
either there is problem elsewhere or I've done something wrong, but with this recompiled library it still shows the exact same error to me.
UPDATE: I've missed few parts where java.lang.management and javax.management is used, I don't know how to do it

Samuel Kroslak
added a comment - May 17 2011 01:33:41 PM UTC - edited Hello,
this is probably related to:
https://jira.mongodb.org/browse/JAVA-291
and the issue is marked as fixed in:
https://jira.mongodb.org/browse/JAVA-170 - but it turned out it's not, as it was said in comments,
I see this was planned for 2.6 but was postponed to 2.7, so my question: is there anything I can do, if I want to use mongodb java driver on android?
I'd love to use it instead of building my own server to act as a REST web service broker between android and mongodb...
now when I try to use it it throws:
05-17 15:36:31.390: ERROR/AndroidRuntime(6748): java.lang.NoClassDefFoundError: com.mongodb.Mongo
I've tried downloading the code and to get rid of all references to java.lang.management.* and javax.management.*
either there is problem elsewhere or I've done something wrong, but with this recompiled library it still shows the exact same error to me.
UPDATE: I've missed few parts where java.lang.management and javax.management is used, I don't know how to do it

Apologies that this has been left unattended for so long. But I'm unsure what we can do about this without removing JMX entirely or resorting to reflection, which has its own risks (as it can be prevented by the security manager). Using the standard Sun VM, the technique used to fix JAVA-170 works just fine:

public class NonExistentClassTest {

public static void main(String[] args) {

Mongo m = null;

try {

m = new Mongo();

} catch (Throwable t) {

System.out.println(t);

}

System.out.println("Here I am");

}

}

Run this code without mongo-java-driver in the classpath and you get this output:

java.lang.NoClassDefFoundError: com/mongodb/Mongo

Here I am

which demonstrates that the VM waits until the actual point of call before attempting to load the class.

It's possible that Dalvik is doing this differently. Can any Android developers confirm this with a full stack trace of the exception?

Jeff Yemin
added a comment - Apr 28 2012 01:51:13 AM UTC Apologies that this has been left unattended for so long. But I'm unsure what we can do about this without removing JMX entirely or resorting to reflection, which has its own risks (as it can be prevented by the security manager). Using the standard Sun VM, the technique used to fix JAVA-170 works just fine:
public class NonExistentClassTest {
public static void main(String[] args) {
Mongo m = null;
try {
m = new Mongo();
} catch (Throwable t) {
System.out.println(t);
}
System.out.println("Here I am");
}
}
Run this code without mongo-java-driver in the classpath and you get this output:
java.lang.NoClassDefFoundError: com/mongodb/Mongo
Here I am
which demonstrates that the VM waits until the actual point of call before attempting to load the class.
It's possible that Dalvik is doing this differently. Can any Android developers confirm this with a full stack trace of the exception?

Jeff Yemin
added a comment - May 02 2012 02:04:03 PM UTC I got the driver to run on Android in the emulator by replacing DynamicMBean with SimplePoolMBean. But the change is not backwards compatible so it will have to wait for a major release.

I've re-evaluated the API change required for this, and I don't think it's significant enough to require a major release. SimplePool class is public but in practice should not really be used by any clients. Moving to 2.9.0.

Jeff Yemin
added a comment - Aug 01 2012 08:12:32 PM UTC I've re-evaluated the API change required for this, and I don't think it's significant enough to require a major release. SimplePool class is public but in practice should not really be used by any clients. Moving to 2.9.0.