InChi and InChiKey by Ajax/JSP

User 68591793e9

15-10-2015 15:45:35

API Java - Jchem 15


 


I can calculate the InChI and InChiKey with Java, but I can't calculate InChI and InChiKey through Ajax with a JSP page. How should I proceed?


 


java.lang.NoSuchMethodError: net.sf.jniinchi.JniInchiWrapper.loadLibrary(Ljava/lang/String;)V


at chemaxon.marvin.io.formats.inchi.Inchi.loadNative(Inchi.java:172)


at chemaxon.marvin.io.formats.inchi.Inchi.install(Inchi.java:75)


at chemaxon.marvin.io.formats.inchi.Inchi.<clinit>(Inchi.java:246)


at chemaxon.marvin.io.formats.inchi.InchiExport.<clinit>(InchiExport.java:35)


at java.lang.Class.forName0(Native Method)


at java.lang.Class.forName(Class.java:264)


at chemaxon.formats.MFileFormat.createExportModule(MFileFormat.java:1123)


at chemaxon.formats.MFileFormatUtil.createExportModule(MFileFormatUtil.java:783)


at chemaxon.formats.MolExporter.init(MolExporter.java:514)


at chemaxon.formats.MolExporter.<init>(MolExporter.java:406)


at chemaxon.formats.MolConverter.init(MolConverter.java:712)


at chemaxon.formats.MolConverter.<init>(MolConverter.java:550)


at chemaxon.formats.MolConverter$Builder.build(MolConverter.java:341)


at MolConvert.MolConvert.gera(MolConvert.java:94)

ChemAxon 2cd598e7ad

19-10-2015 13:49:08

Hi,


Could you please clarify your usage, in what circumstances would you like to call that function? It seems that the inchi library is not found on the Molconvert's host machine. For some reference: Chemaxon InChI Documentation.


Regards,
Domi

User 68591793e9

20-10-2015 18:37:07

In Java the code below works:


public static void main(String[] args) {

        String smiles = "CCC";


        OutputStream fs = new ByteArrayOutputStream();


        MolConverter.Builder mcbld = new MolConverter.Builder();
        mcbld.addInput(new ByteArrayInputStream(smiles.getBytes()), "smiles");
        mcbld.setOutputFlags(MolExporter.TEXT);
        mcbld.setOutput(fs, "inchikey");

        try {
                MolConverter mc = mcbld.build();
                mc.convert();
                mc.close();
        } catch (IOException e) {
                e.printStackTrace();
        }


        System.out.println(fs.toString());
}


OUTPUT: InChIKey=ATUOYWHBWRKTHZ-UHFFFAOYSA-N


 


But in JSP the same code does not work:


<%
String smiles = "CCC";


        OutputStream fs = new ByteArrayOutputStream();


        MolConverter.Builder mcbld = new MolConverter.Builder();
        mcbld.addInput(new ByteArrayInputStream(smiles.getBytes()), "smiles");
        mcbld.setOutputFlags(MolExporter.TEXT);
        mcbld.setOutput(fs, "inchikey");

        try {
                MolConverter mc = mcbld.build();
                mc.convert();
                mc.close();
        } catch (IOException e) {
                e.printStackTrace();
        }


        out.write(fs.toString());
%>


OUTPUT: 


Exception in thread "main" java.lang.NoSuchMethodError: net.sf.jniinchi.JniInchiWrapper.loadLibrary(Ljava/lang/String;)V
at chemaxon.marvin.io.formats.inchi.Inchi.loadNative(Inchi.java:172)
at chemaxon.marvin.io.formats.inchi.Inchi.install(Inchi.java:75)
...

User 68591793e9

22-10-2015 02:25:00

Find out where was the bug!


 


My team was also using the API Chemistry Development Kit (CDK version 0.99.1) containing another version of Chemaxon net.sf.jniinchi package containing the JniInchiWrapper class. This conflict was generating the NoSuchMethodError.


 


I removed the .jar package of CDK and began to work.


 


But...


 


When I use MolConvert to generate InChiKey, it creates a directory and a .dll file in C:\Users\{username}\chemaxon\lib\inchi-1.3\inchi64.dll


 


Everything works normally, but if I restart Tomcat, gives the following error: Native Library C:\Users\{username}\chemaxon\lib\inchi-1.3\inchi64.dll already loaded in another classloader


 


Why does it happen? How to fix it?


 


I am using:


Windows 10


Tomcat 7.0.61


Java 8


API Jchem 15.9.7.0

ChemAxon 2c555f5717

26-10-2015 11:06:45

Dear Silasyudi12!


   Unfortunately I could not reproduce you problem. Could you provide us a stacktrace? Or could you send what processes use the dll? (For example with this tool: https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx )


   It is also possible that the resource is used by multiple class loaders in tomcat, and for that there might be a workaround by adding the required library to the /lib folder and this way this library is shared between all the classloaders of tomcat.


   I hope we can move forward with your issue.


Regards:
Balázs 

User 68591793e9

03-12-2015 18:41:37




The problem occurs only on Windows. I tested on Linux and works normally.


ChemAxon a202a732bf

08-12-2015 15:10:12

Hi Silas!


Do I understand correctly that you moved to Linux and you do not need a solution on Windows? If not, please, provide the stacktrace of the exception thrown (that Balázs asked in his earlier reply).


Regards,


Zsuzsa