如何将sqljdbc_auth.dll添加到我的maven项目中

Kad*_*med 9 java sql-server netbeans jdbc maven

我正在尝试建立与数据库的连接.这是一个使用maven的简单项目.我有问题sqljdbc_auth.dll

我添加了mssql jdbc驱动程序并添加了依赖项 pom.xml

    <dependency>
    <groupId>com.microsoft</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>4.0.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

这是我的尝试块

    try {
        // Establish the connection. 
        SQLServerDataSource ds = new SQLServerDataSource();
        ds.setIntegratedSecurity(true);
        ds.setServerName("BUILDSRV");
        ds.setDatabaseName("master");
                    ds.setIntegratedSecurity(true);
        con = ds.getConnection();       
        }
Run Code Online (Sandbox Code Playgroud)

我有一个错误

    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:
Run Code Online (Sandbox Code Playgroud)

我有我的sqljdbc_auth.dll但我不需要把它放到我的C:\windows\... 我需要在maven的项目中添加它.我怎样才能做到这一点?

我试图将它添加到它pom.xml但它不起作用

    <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>
Run Code Online (Sandbox Code Playgroud)

我在建造时遇到了另一个错误

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]
Run Code Online (Sandbox Code Playgroud)

mzz*_*zzb 0

我认为你不需要使用maven-helper-plugin这里。这里的文档说您需要安装dll 或在系统变量中指定其路径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目录中

然后,当您运行应用程序时,将系统属性作为命令行参数传递java -Djava.library.path=.

如果您不想通过命令行传递参数 - 您可以使用提取当前工作目录System.getProperty("user.dir"))并按照此处所述的步骤在方法中以编程方式将您的目录设置java.library.path为当前目录main