[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Help needed for calling Java class from R



* Andreas Tille:

> On Tue, Apr 14, 2020 at 06:52:56PM +0200, Florian Weimer wrote:
>> * Andreas Tille:
>> > ERROR: loading failed
>> > * removing '/build/r-cran-rcdk-3.5.0/debian/r-cran-rcdk/usr/lib/R/site-library/rcdk'
>> > dh_auto_install: error: R CMD INSTALL -l /build/r-cran-rcdk-3.5.0/debian/r-cran-rcdk/usr/lib/R/site-library --clean . "--built-timestamp='Mon, 23 Mar 2020 21:27:30 +0100'" returned exit code 1
>> > make: *** [debian/rules:4: binary] Error 25
>> > dpkg-buildpackage: error: debian/rules binary subprocess returned exit status 2
>> > I: copying local configuration
>> > E: Failed autobuilding of package
>> >
>> >
>> > I verified in the pbuilder chroot that the missing class exists in CLASSPATH:
>> >
>> > root:/# grep NitrogenRule /usr/share/java/*
>> > Binary file /usr/share/java/cdk-formula-2.3.jar matches
>> > Binary file /usr/share/java/cdk-formula.jar matches
>> 
>> Please check if /usr/share/java/cdk-interfaces.jar is on the
>> classpath.  The missing class is
>> org.openscience.cdk.exception.CDKException (apparently a
>> superinterface of org.openscience.cdk.formula.rules.NitrogenRule), and
>> it's contained in that JAR file.
>
> This is a good hint.  So I tried:
>
>
> $ git diff
> diff --git a/debian/rules b/debian/rules
> index 529c38a..bde1d1b 100755
> --- a/debian/rules
> +++ b/debian/rules
> @@ -1,5 +1,6 @@
>  #!/usr/bin/make -f
>  
> +export CLASSPATH=/usr/share/java/cdk-interfaces.jar:/usr/share/java/cdk-silent.jar
> +
>  %:
>         dh $@ --buildsystem R
>
>
> and while the first error vanished that way I get the next one:
>
>
> *** installing help indices
> ** building package indices
> ** installing vignettes
> ** testing if installed package can be loaded from temporary location
> Error: package or namespace load failed for 'rcdk':
>  .onLoad failed in loadNamespace() for 'rcdk', details:
>   call: .jcall("org/openscience/cdk/silent/SilentChemObjectBuilder", 
>   error: RcallMethod: cannot determine object class

Meh.  Does R have exceptions?  It would be nice to translate the
underlying exception from

  if (clnam)
    cls = findClass(env, clnam, oClassLoader);
  else
    cls = objectClass(env,o);
  if (!cls)
    error_return("RcallMethod: cannot determine object class");

into an R exception with a nice backtrace, then we might see *why* the
class fails to load (like the missing superinterface before).

We can try to actually load the class using the classpath you used and
some Java tools:

# jshell --class-path /usr/share/java/cdk-interfaces.jar:/e/java/cdk-silent.jar
|  Welcome to JShell -- Version 11.0.7-ea
|  For an introduction type: /help intro

jshell> org.openscience.cdk.silent.SilentChemObjectBuilder.class.newInstance()
|  Exception java.lang.NoClassDefFoundError: org/openscience/cdk/DynamicFactory$CreationModifier
|        at Class.getDeclaredConstructors0 (Native Method)
|        at Class.privateGetDeclaredConstructors (Class.java:3137)
|        at Class.getConstructor0 (Class.java:3342)
|        at Class.newInstance (Class.java:556)
|        at (#1:1)
|  Caused by: java.lang.ClassNotFoundException: org.openscience.cdk.DynamicFactory$CreationModifier
|        at BuiltinClassLoader.loadClass (BuiltinClassLoader.java:581)
|        at ClassLoaders$AppClassLoader.loadClass (ClassLoaders.java:178)
|        at ClassLoader.loadClass (ClassLoader.java:522)
|        ...

That error goes away if I add /usr/share/java/cdk-core.jar to the
classpath.  Hopefully that gets past this point.  (The jshell command
will still fail, but now because JDK can load the class and sees that
the constructor has private access and cannot be called.  Hopefully
that's not relevant in the real scenario.)

There's probably some better way to deal with this using Maven, but I
really dislike Maven and have carefully avoided to learn much about it
so far, sorry. 8-(


Reply to: