Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
712 views
in Technique[技术] by (71.8m points)

java - Native Library sqljdbc_auth.dll already loaded in another classloader

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:WINDOWSsystem32
  • C:Program FilesApache Software FoundationTomcat 7.0in

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

  • /WEB-INF/lib directory of each web application
  • C:Program FilesApache Software FoundationTomcat 7.0lib

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 |
|----------------------------------|

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...