dan2097 / jna-inchi

Wrapper to access InChI from Java
GNU Lesser General Public License v2.1
9 stars 7 forks source link

Runtime exception within Tomcat #17

Closed ChemMitch closed 2 years ago

ChemMitch commented 2 years ago

This is more of a question than anything else. I recently modified a Java 8 application to use jna-inchi. It works fine locally but when called from a servlet running under Tomcat, there is an exception: java.lang.NoClassDefFoundError: Could not initialize class io.github.dan2097.jnainchi.inchi.InchiLibrary

First noticed this error on my Windows laptop and was able to get rid of the error by extracting the appropriate dll from the platform-specific JAR (jna-inchi-win32-x86-64-1.0.1.jar) and copying it to tomcat/bin. On the production Linux server, the same strategy didn't work. (Extracted and copied the .so file from the corresponding JAR files to tomcat/bin.)

So, what I'm looking to find out: has anyone else come across the java.lang.NoClassDefFoundError: Could not initialize class io.github.dan2097.jnainchi.inchi.InchiLibrary when running an application that uses jna-inchi under Tomcat on Linus? How do you avoid the error?

dan2097 commented 2 years ago

I've not encountered an issue like that thus far. Just tried the opsin-ws project, which uses JNA-InChI, on Windows Tomcat 9, and Linux (Centos) Tomcat 8.5

Which version of Tomcat are you using? and does the error log provide any more specifics on the error? The loading of the native code is done when InchiLibrary is first called in static code, so if this fails I think one does expect to get a NoClassDefFoundError

Presumably there's nothing exotic about the processor architecture of the Linux server?

ChemMitch commented 2 years ago

This is Tomcat 7. As far as I know, it's a pretty vanilla Intel Linux server. The complete stack trace is below. I couldn't find anything else in the logs.

Do you think it might be useful testing out Tomcat 9?

SEVERE: Servlet.service() for servlet [Resolver] in context with path [/resolverInternal0910I] threw exception [Servlet execution threw an exception] with root cause java.lang.NoClassDefFoundError: Could not initialize class io.github.dan2097.jnainchi.inchi.InchiLibrary at io.github.dan2097.jnainchi.inchi.IxaFunctions.IXA_STATUS_Create(IxaFunctions.java:100) at io.github.dan2097.jnainchi.JnaInchi.toInchi(JnaInchi.java:65) at io.github.dan2097.jnainchi.JnaInchi.toInchi(JnaInchi.java:50) at gov.nih.ncgc.chemical.Chemical.getSTDInchi(Chemical.java:783) at gov.nih.ncgc.chemical.Chemical.getSTDInchiKey(Chemical.java:697) at gov.nih.ncgc.resolver.calculators.InchiKeyCalculator.calculate(InchiKeyCalculator.java:16) at gov.nih.ncgc.resolver.calculators.InchiKeyCalculator.calculate(InchiKeyCalculator.java:5) at gov.nih.ncgc.resolver.calculators.SingleParameterAbstractChemicalCalculator.calculate(SingleParameterAbstractChemicalCalculator.java:59) at gov.nih.ncgc.resolver.calculators.ChemicalCalculator$1.lambda$calculate$0(ChemicalCalculator.java:97) at gov.nih.ncgc.resolver.Resolver$10.lambda$null$0(Resolver.java:1434) at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:566) at gov.nih.ncgc.resolver.Resolver$10.lambda$encode$1(Resolver.java:1435) at gov.nih.ncgc.resolver.Resolver.doGet(Resolver.java:1776) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:492) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:165) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1201) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:654) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:317) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

dan2097 commented 2 years ago

Tomcat 7 is now EOL (https://tomcat.apache.org/whichversion.html) so it's probably worth a shot. There is a breaking change between Tomcat 9 and 10 (https://tomcat.apache.org/migration-10.html), while the changes in Tomcat 8 or 9 are unlikely to effect upgrading.

dan2097 commented 2 years ago

@ChemMitch Did you get a chance to try a later version of Tomcat?

ChemMitch commented 2 years ago

Thanks for asking, Daniel. Yes; we got the latest jna-inchi working fine.

dan2097 commented 2 years ago

Perfect