【发布时间】:2012-11-09 19:39:03
【问题描述】:
我正在尝试建立与数据库的连接。这是一个使用 maven 的简单项目。
sqljdbc_auth.dll 有问题
我已经添加了mssql jdbc驱动并在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 将它添加到我的项目中。我该怎么做?
我尝试将其添加到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>
我在构建时遇到另一个错误
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]
【问题讨论】:
-
您打算如何使用您的应用程序,是 webapp 还是独立部署?
-
显然你不能在你的jar中添加dll,如果可能的话,它会首先进入jdbc jar本身,为你省去所有的麻烦。我们可能有一个解决方案,具体取决于您打算如何使用您的应用
-
不是网络。但是我不能说它是独立的,因为我不明白它的意思)
-
我的意思是说你是如何开始你的程序的。像
java MyClass或mvn exec:java ...或在一些网络容器中。以及如何分发您的项目,作为 jar 分发? -
现在我在 netbeans ide 中启动 java myclass。但将来我会有很多模块
标签: java sql-server maven netbeans jdbc