JMuPDF class loading trouble

Hello all.

I am trying to access the JMuPDF java library from jruby and am having
some trouble. As I am not a Java expert and only have a little
experience accessing java functionality from jruby I was hoping someone
could point out what I am doing wrong.

The JMuPDF library can be found here:


The JMuPDF tutorial I am trying to port to JRuby along with the error
can be read here: https://gist.github.com/1156073

Requiring the jar file causes no trouble ; it is when I try to actually
use the Java classes that things go wrong.

I have used the same setup with iText without trouble so I am not sure
why it is failing with this one.

Could anyone point out what I am doing wrong? If anyone has any examples
of using JMuPDF from JRuby I would be grateful if they could be shared.

Cheers

Jeff

You need to use java_import to be able to access the class you are
trying to
access. So after your require statements, do something like this:

java_import ‘com.jmupdf.PdfDocument’
pdf_file = PdfDocument.new(File.read(‘test.pdf’).to_java_bytes)

That should work for you.

Actually, since he was using the com.jmupdf.PdfDocument inline he does
not need to do an import (although it is never a bad practice). This
sort of error is usually from one of two things:

  1. Dependent jar on the library you are using is not in the CLASSPATH
  2. You are using some native library that needs java.library.path set.

-Tom

On Fri, Aug 19, 2011 at 7:32 PM, Joseph A. [email protected]
wrote:

I am trying to access the JMuPDF java library from jruby and am having
use the Java classes that things go wrong.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


blog: http://blog.enebo.com twitter: tom_enebo
mail: [email protected]

Hello all

I went for the full inline call to reduce moving parts in the
application.

The .jar file does rely on a .so / .dll file (pick your poison) so I had
a look at java.library.path and changed the command line invocation to
be:

jruby -J-Djava.library.path=/path/to/dir/with/so/file/in/it/ test.rb

Which, as far as I have read, should make sure that the .so file in that
directory is being picked up. However the same error is still appearing.

As far as I have read from the documentation there are no other
dependencies in terms of Jars. Does anyone have another other ideas /
suggestions?

Cheers

Jeff

Hello Charles,

Thanks for the suggestions. I should have tried the -d option earlier
but my mind tends to turn off once I am out of ruby-land. I have added
the full output of that command to the gist at
https://gist.github.com/1156073

Not sure if it is important but the directory I am adding to the
java.library.path has two .so files in it. One for 32bit
(libjmupdf32.so) and one for 64 bit operating systems (libjmupdf64.so),
I am currently on a 64bit Linux.

Thanks

Jeff

Hello all,

Apologies for dragging up an old thread but I haven’t been able to make
any progress on this and thought I would ask again since my last email
included new information (output from the -d option for a full stack
trace).

I don’t suppose there are any Java guys in the room willing to give it
another look?

cheers

Jeff

It appeared that the .so files were not being loaded.

Copying the .so files (and the jar, not sure if necessary) into the
linux /lib directory sorted it.

Information here:
https://sourceforge.net/tracker/?func=detail&aid=3430998&group_id=383710&atid=1595531

On Sun, Aug 21, 2011 at 7:23 PM, Jeffrey J. [email protected]
wrote:

The .jar file does rely on a .so / .dll file (pick your poison) so I had a
look at java.library.path and changed the command line invocation to be:

jruby -J-Djava.library.path=/path/to/dir/with/so/file/in/it/ test.rb

Which, as far as I have read, should make sure that the .so file in that
directory is being picked up. However the same error is still appearing.

If it is indeed a problem loading the .so, it could be due to JRuby
itself being loaded into the bootstrap classloader. Can you run the
same test with -d? We may be able to get more information out of the
load process, such as the actual error it’s getting loading the class
in question.

  • Charlie