Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native Library sqljdbc_auth.dll already loaded in another classloader

Tags:

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?

like image 818
Gustavo Avatar asked May 17 '12 14:05

Gustavo


2 Answers

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 |
|----------------------------------|
like image 195
Chris White Avatar answered Dec 14 '22 23:12

Chris White


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
like image 20
pd40 Avatar answered Dec 15 '22 00:12

pd40