Reputation: 1
I'm writing java desktop application which will be launched using web start. The application connect to MS SQL Server using Windows authentication. My problem is that, to do this, my program need sqljdbc_auth.dll. On my computer I can set java.library.path like this and it work's fine
-Djava.library.path="<MyPath>\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\auth\x86"
also loading library like this work's properly
System.loadLibrary("sqljdbc_auth");
but there is a problem when I try to load this DLL with Web start. I add dll to my project(/dll/sqljdbc_auth.dll) and save it in client computer like this:
static {
try {
System.loadLibrary(SQL_AUTHENTICATION_DLL);
} catch (UnsatisfiedLinkError exception) {
loadLib();
}
}
/**
* Puts library to temp dir and loads to memory.
*/
private static void loadLib() {
String name = SQL_AUTHENTICATION_DLL + ".dll";
try {
java.io.InputStream isInputStream = SQLServer.class.getResourceAsStream("/dll/" + name);
java.io.File fileOut = new java.io.File(System.getProperty("java.io.tmpdir") + name);
java.io.OutputStream osOutputSteream = org.apache.commons.io.FileUtils.openOutputStream(fileOut);
org.apache.commons.io.IOUtils.copy(isInputStream, osOutputSteream);
isInputStream.close();
osOutputSteream.close();
System.load(fileOut.toString());
} catch (UnsatisfiedLinkError | java.io.IOException exception) {
java.util.logging.Logger.getLogger(
java.util.logging.Logger.GLOBAL_LOGGER_NAME).log(
java.util.logging.Level.SEVERE,
"Failed to load " + name , exception);
}
}
Code execute properly, but the DLL is not loaded. I get such warning
paź 30, 2013 10:04:45 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
and then exception
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication.
What am I doing wrong? What else should I do to load it properly?
This is my jnlp file. I check what you want me to check and everything seems to be ok, but still doesn't work. Do I have to extract the dll somewhere? If yes where exacly? File sqljdbc_auth.jar is in the same directory as main file Compliance_Mirror.jar.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="http://spplapp03252:8080/prog/ " href="launch.jnlp" spec="1.0+">
<information>
<title>Compliance Mirror</title>
<vendor>B0635410</vendor>
<homepage href=""/>
<description>Compliance Mirror</description>
<description kind="short">Compliance Mirror</description>
</information>
<update check="always"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.7+"/>
<jar href="Compliance_Mirror.jar" main="true"/>
<nativelib href="sqljdbc_auth.jar"/>
<jar href="lib/poi-ooxml-schemas-3.9-20121203.jar"/>
<jar href="lib/poi-3.9-20121203.jar"/>
<jar href="lib/poi-ooxml-3.9-20121203.jar"/>
<jar href="lib/dom4j-1.6.1.jar"/>
<jar href="lib/stax-api-1.0.1.jar"/>
<jar href="lib/xmlbeans-2.3.0.jar"/>
<jar href="lib/commons-codec-1.5.jar"/>
<jar href="lib/commons-logging-1.1.jar"/>
<jar href="lib/junit-3.8.1.jar"/>
<jar href="lib/log4j-1.2.13.jar"/>
<jar href="lib/jxl.jar"/>
<jar href="lib/commons-io-2.4.jar"/>
<extension href="jnlpcomponent2.jnlp"/>
<extension href="jnlpcomponent1.jnlp"/>
</resources>
<application-desc main-class="compliance.mirror.MainClass">
</application-desc>
</jnlp>
Upvotes: 0
Views: 2582
Reputation: 11911
You are copying the dll to the tempdir which obviously isn't on java's library-path.
When using webstart the best way to add a dll is to pack it into an extra jar and add it as a nativelib
into your jnlp file:
<jnlp>
...
<resources>
...
<nativelib href="mydlljar.jar" />
...
</resources>
...
</jnlp>
Then System.loadLibrary()
should work without problems.
Upvotes: 2