Path: csiph.com!goblin3!goblin2!goblin.stu.neva.ru!aioe.org!bofh.it!news.nic.it!robomod From: Florian Weimer Newsgroups: linux.debian.maint.java Subject: Re: Help needed for calling Java class from R Date: Tue, 14 Apr 2020 20:50:01 +0200 Message-ID: References: X-Mailbox-Line: From debian-java-request@lists.debian.org Tue Apr 14 18:50:00 2020 Old-Return-Path: X-Amavis-Spam-Status: No, score=-8 tagged_above=-10000 required=5.3 tests=[BAYES_00=-2, DIGITS_LETTERS=1, FOURLA=0.1, LDO_WHITELIST=-5, MURPHY_DRUGS_REL6=0.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=unavailable autolearn_force=no X-Policyd-Weight: using cached result; rate:hard: -4.6 MIME-Version: 1.0 Content-Type: text/plain X-Mailing-List: archive/latest/22132 List-ID: List-URL: List-Archive: https://lists.debian.org/msgid-search/87o8rtlx6f.fsf@mid.deneb.enyo.de Approved: robomod@news.nic.it Lines: 96 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Cc: debian-r@lists.debian.org, Debian Java List X-Original-Date: Tue, 14 Apr 2020 20:49:44 +0200 X-Original-Message-ID: <87o8rtlx6f.fsf@mid.deneb.enyo.de> X-Original-References: <20200414161011.GD22823@an3as.eu> <877dyim2l3.fsf@mid.deneb.enyo.de> <20200414175354.GF22823@an3as.eu> Xref: csiph.com linux.debian.maint.java:11568 * 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-(