[jsword-devel] Is it possible to turn off new Lucene jars use of ManagementFactory

Martin Denham mjdenham at gmail.com
Sat Dec 4 15:10:21 MST 2010


Unfortunately Android does not have java.lang.management.ManagementFactory

The old version of Lucene never required it but the new version of Lucene
does.

12-04 21:34:41.629: WARN/System.err(23160): java.lang.NoClassDefFoundError:
java.lang.management.ManagementFactory
12-04 21:34:41.639: WARN/System.err(23160):     at
org.apache.lucene.store.NativeFSLockFactory.acquireTestLock(NativeFSLockFactory.java:87)
12-04 21:34:41.639: WARN/System.err(23160):     at
org.apache.lucene.store.NativeFSLockFactory.makeLock(NativeFSLockFactory.java:142)
12-04 21:34:41.649: WARN/System.err(23160):     at
org.apache.lucene.store.Directory.makeLock(Directory.java:106)
12-04 21:34:41.649: WARN/System.err(23160):     at
org.apache.lucene.index.IndexWriter.init(IndexWriter.java:1058)

I can't really see a reason to use ManagementFactory but here is how it is
used:

private synchronized void acquireTestLock() {
    if (tested) return;
    tested = true;

    // Ensure that lockDir exists and is a directory.
    if (!lockDir.exists()) {
      if (!lockDir.mkdirs())
        throw new RuntimeException("Cannot create directory: " +
                              lockDir.getAbsolutePath());
    } else if (!lockDir.isDirectory()) {
      throw new RuntimeException("Found regular file where directory
expected: " +
                            lockDir.getAbsolutePath());
    }

    // add the RuntimeMXBean's name to the lock file, to reduce the chance for
    // name collisions when this code is invoked by multiple JVMs (such as in
    // our tests). On most systems, the name includes the process Id.
    // Also, remove any non-alphanumeric characters, so that the lock file will
    // be created for sure on all systems.
    String randomLockName = "lucene-"
        + ManagementFactory.getRuntimeMXBean().getName().replaceAll("[^a..zA..Z0..9]+","")
+ "-"
        + Long.toString(new Random().nextInt(), Character.MAX_RADIX)
        + "-test.lock";


I suppose I could edit the code and build a modified Lucene jar but I
don't really want to do that.  Another solution might be to go back to
earlier jars but again that would lead to differences with JSword.  I
suppose I could disable index creation on Android because the above is
only required during index creation.  At the moment all I can think of
is to modify the Lucene jars.


Any ideas?


Thanks

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20101204/9ed54054/attachment.html>


More information about the jsword-devel mailing list