I have a Java application that needs to run as a Windows service. The application needs to connect to Microsoft SQL server using Integrated Security. This means that Java needs to have the location of the driver dll in the java library path.
According to the prunsrv documentation, it is possible to pass in JVM options using the following parameter:
++JvmOptions="-Djava.library.path=drivers/MS SQL/x64"
where the path above is specific to my case.
When running the application using java.exe from a command line, and passing in the same library path as above (with the appropriate java syntax), it works exactly as expected. However, when running the application as a service (using jvm mode in prunsrv) it gives the following exception and does not connect:
com.microsoft.sqlserver.jdbc.SQLServerException:
This driver is not configured for integrated authentication. com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
...
Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
...
The exception is the same as when the "-Djava.library.path=drivers/MS SQL/x64" options is left out from the console application. It seems like the service is not setting the library path as expected.
Upon reviewing the documentation for prunsrv there is an option that looks promising:
--LibraryPath : Directory added to the search path used to locate the DLLs for the JVM. This directory is added both in front of the PATH environment variable and as a parameter to the SetDLLDirectory function.
This is exactly what I want.
Sadly, when setting this option along with the java.library.path jvm option, it still throws the exact same exception as before. It's as if it hasn't applied the setting.