如何将sqljdbc_auth.dll添加到我的Maven项目 [英] how to add sqljdbc_auth.dll to my maven project
问题描述
我正在尝试建立与数据库的连接.这是一个使用maven的简单项目.
我在sqljdbc_auth.dll
I am trying to establish connection to database. It's a simple project with using maven.
I have problems with sqljdbc_auth.dll
我添加了mssql jdbc驱动程序,并在pom.xml
I have added mssql jdbc driver and added a dependency in pom.xml
<dependency>
<groupId>com.microsoft</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>4.0.0</version>
</dependency>
这是我的尝试块
try {
// Establish the connection.
SQLServerDataSource ds = new SQLServerDataSource();
ds.setIntegratedSecurity(true);
ds.setServerName("BUILDSRV");
ds.setDatabaseName("master");
ds.setIntegratedSecurity(true);
con = ds.getConnection();
}
我有一个错误
21.11.2012 18:07:04 com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException:
我有我的sqljdbc_auth.dll
,但无需将其放入我的C:\windows\...
我需要从maven将其添加到我的项目中.我该怎么办?
I have my sqljdbc_auth.dll
but I don't need to put it to my C:\windows\...
I need to add it in my project from maven. How can I do this?
我试图将其添加到pom.xml
,但是它不起作用
I tried to add it to the pom.xml
but it doesn't work
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>attach-artifacts</id>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<file>target</file>
<type>dll</type>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
我在构建时遇到另一个错误
I got another error while building
Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.1:attach-artifact (attach-artifacts) on project mavenproject1dbconnect: Unable to parse configuration of mojo org.codehaus.mojo:build-helper-maven-plugin:1.1:attach-artifact for parameter file: Cannot configure instance of org.codehaus.mojo.buildhelper.Artifact from target -> [Help 1]
推荐答案
我不认为您需要在此处使用maven-helper-plugin
.
此处的文档说您需要安装 dll或在系统变量java.library.path
中指定其路径.
i dont think you need to use the maven-helper-plugin
here.
The doc here says you either need to install the dll or specify its path in the system variable java.library.path
.
看看 http://msdn.microsoft.com/en-us/library/ms378428 .aspx#Connectingintegrated
更新:
确保dll与jar一起分发.如果您使用的是Maven,
将dll文件放在src/main/resources文件夹中.然后通过将dll从包中排除来确保dll最终在jar之外.请按照与此处所述的步骤相似的步骤进行操作.之后,您应该将dll和内置的jar文件放在target
目录
UPDATE:
make sure the dll is distributed along with your jar. If you are using a maven,
Put the dll file in your src/main/resources folder. Then make sure the dll ends up outside the jar by excluding it from the package. Follow steps similar to ones outlined here. After this you should have your dll along with your built jar file in target
directory
然后,当您运行应用程序时,将系统属性作为命令行参数java -Djava.library.path=.
传递.
Then when you run the app pass system properties as commandline parameter java -Djava.library.path=.
.
如果您不想打扰通过命令行传递参数,则可以使用System.getProperty("user.dir"))
提取当前工作目录,并按照
If you prefer not to bother passing parameters via commandline -- you can extract current working directory using System.getProperty("user.dir"))
and follow steps as stated here to set your java.library.path
to current dir programatically in your main
method
这篇关于如何将sqljdbc_auth.dll添加到我的Maven项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!