Native Library sqljdbc_auth.dll already loaded in another classloader
Asked Answered
H

3

24

I have 2 java web apps that need to connect to SQL Server Database using Windows Integrated Authentication.

The first one that is loaded works fine but the second one throws the exception:

Native Library sqljdbc_auth.dll already loaded in another classloader

The error above occurs when I place the sqljdbc_auth.dll in one of the folders:

  • C:\WINDOWS\system32\
  • C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\

If I place the sqljdbc_auth.dll in one of the folders below:

  • /WEB-INF/lib directory of each web application
  • C:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\

Both apps throw the exception:

Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path

I am using this code to load the driver:

Class.forName("jdbc:sqlserver://<HOST>;databaseName=<DBNAME>;integratedSecurity=true;");

How can I solve it?

Hague answered 17/5, 2012 at 14:24 Comment(0)
T
34

Each web application has its own Classloader (isolating them). When you call the Class.forName() method, there is a static block which is trying to load the shared library (dll file) - so both your web apps are trying to load the shared lib, hence the error message when the second one attempts to load.

The JDBC jar you have for sqlserver should be moved from being bundled with your wars, to the tomcat 7.0/lib folder and copy the sqljdbc_auth.dll to tomcat/bin folder - this way it will be in the tomcat parent classloader, and the class will only be loaded once.

|----------------------------------|
| sqljdbc*.jar     --> tomcat*/lib |
|----------------------------------|
| sqljdbc_auth.dll --> tomcat*/bin |
|----------------------------------|
Thermo answered 17/5, 2012 at 23:54 Comment(5)
As I said in my question I tried to put the DLL in tomcat 7.0/lib before. After your answer, I created the tomcat 7.0/libs and put the DLL there, and I got the same error: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.pathHague
I've read about the Tomcat Classloader before in the link: tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html But it seems that the Tomcat only loads the .jar files, not the .dll files.Hague
Ok, to clarify, you need to put the dll in the Tomcat/bin folder and the jdbc JAR file in the Tomcat/lib folder (sorry my mistake on the extra s on lib, which i've now corrected)Thermo
And in addition, Tomcat loads the jar files, which then in turn load the dll file (but the classpath and native library paths are different)Thermo
Nice explanation, thanks! In addition to adding the jar to the tomcat*/lib folder, the jar needs to be removed from the application's dependencies. Then using multiple applications with integrated security works as expected!Gadfly
G
1

I think you are on the right track.

For command line startup you can easily solve the no sqljdbc_auth in java.library.path issue by setting the environment variable

CATALINA_OPTS=-Djava.library.path=/path/to/dll

If you are running tomcat as a service, change the Options parameter under

HKEY_LOCAL_MACHINE\SOFTWARE\Apache Software Foundation\Procrun 2.0\Tomcat7\Parameters\Java

to include:

-Djava.library.path=/path/to/dll
Grubb answered 18/5, 2012 at 10:30 Comment(0)
M
0

The same error occurs in Jasper Studio.

Probably not the best solution but place the sqljdbc4.jar in C:\Program Files (x86)\TIBCO\Jaspersoft Studio-6.1.0.final\features\jre.win32.win32.x86.feature_1.7.0.u80\jre\lib\ext and the sqljdbc_auth.dll in C:\Program Files (x86)\TIBCO\Jaspersoft Studio-6.1.0.final\features\jre.win32.win32.x86.feature_1.7.0.u80\jre\bin

And it will work.

Monitory answered 24/8, 2016 at 6:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.