java - Executable Jar with Dependency on dll -
i attempting deploy swing application uses dll facilitate database connection (using sqljdbc4 jar depends on sqljdbc_auth.dll). deployment strategy creating executable jar file. problem cannot functions rely on sqljdbc_auth.dll work in executable jar create.
i can project working fine in eclipse using of following methods:
- reference folder containing dll in build path configuration specifying native library location on source folder
- put dll in c:\windows\system32 directory
- add following vm argument referencing relative path of dll folder in project "-djava.library.path=path/to/dllfolder"
the 4th method have tried load dll directly in code via following line. system.load("c:/users/me/desktop/sqljdbc_auth.dll");
have been unsuccessful approach , following error.
mar 20, 2015 4:18:44 pm com.microsoft.sqlserver.jdbc.authenticationjni <clinit> warning: failed load sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
however, error doesn't come directly line of code loads library, seems come afterwards when sqljdbc library trying load dll use in making connection.
either way, cannot of above methods working when deploy app executable jar file via export functionality of eclipse. thing can mentioned error message.
the following sample application produces same result.
public class testapp { public static void main(string[] args){ swingutilities.invokelater(new runnable(){ public void run(){ jframe mainframe = new jframe(); mainframe.setsize(300,300); mainframe.setlocationrelativeto(null); mainframe.setdefaultcloseoperation(jframe.exit_on_close); mainframe.setvisible(true); try{ //system.load("c:/users/me/desktop/sqljdbc_auth.dll"); string servername = "local"; string databasename = "test_database"; string connstring = "jdbc:sqlserver://" + servername + "; databasename=" + databasename + ";integratedsecurity=true"; class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); connection conn = drivermanager.getconnection(connstring); statement st = conn.createstatement(); resultset rs = st.executequery("select distinct name test_table"); rs.next(); joptionpane.showmessagedialog(null, "from db: " + rs.getstring(1), "test", joptionpane.information_message); } catch (sqlexception e) { e.printstacktrace(); joptionpane.showmessagedialog(null, e.getmessage(), "test", joptionpane.information_message); } catch (classnotfoundexception e) { e.printstacktrace(); joptionpane.showmessagedialog(null, e.getmessage(), "test", joptionpane.information_message); } catch (exception e){ e.printstacktrace(); joptionpane.showmessagedialog(null, e.getmessage(), "test", joptionpane.information_message); } } }); }
}
i've read tons of posts on using dlls executable jars , seem reference using system.load method. ironically, 1 thing can't working. know have right dll; however, because can other methods work in ide environment. don't care if dll packaged executable jar or not, want work!
i presume has putting dll's in library
(in eclipse, properties->java build path->libraries).
when export jar, have option of exporting library files folder.
if decompile jar after that, you'll notice there's manifest file, , in it, paths library files (based on export, created library folder you, jarname_lib).
when export, have option save ant file, can edit change export location of library files folder name of choice. can add edited ant file build happens whenever build project:
(in eclipse, properties->builders->new)
Comments
Post a Comment