问题描述
我有一个Java应用程序,已分发给几个用户.该应用程序使用Windows身份验证连接到SQLServer数据库.摘自几篇SO-Posts( SO6938717 ,SO17277001 ),我了解到通常的做法是在VM参数中设置所需库的路径.
I have a Java Application which is distributed to a few users. The application connets to a SQLServer Database using windows authentification.From several SO-Posts (SO6938717, SO17277001) I learned that it is common practice to set a path to the needed library in the VM arguments.
java -Djava.library.path =/path/to/my/dll -jar/my/classpath/goes/here MainClass
java -Djava.library.path=/path/to/my/dll -jar /my/classpath/goes/here MainClass
我的应用程序在32位和64位环境上运行,但是对于每种环境,都有一个具有相同名称的特定库:sqljdbc_auth.dll.
My Application runs on 32- and 64bit environments, but for every environment there is a specific library with the same name: sqljdbc_auth.dll.
我可以将两个路径设置为VM参数:java -Djava.library.path =/auth/x86;/auth/x64 -jar/my/classpath/goes/here MainClass
I can set two paths as VM arguments:java -Djava.library.path=/auth/x86;/auth/x64 -jar /my/classpath/goes/here MainClass
但这不起作用.如何确保Windows身份验证在32位和64位环境中工作?
But this doesn't work. How can I ensure, that windows authentification works in 32- and 64bit environments?
推荐答案
在这里看看:
possible-values-of-processor-architecture
考虑到这一点,您可以通过以下方式分发应用程序:
With this in mind you can distribute your app this way:
/libs/yourjarfiles.jar
/AMD64/sqljdbc_auth.dll (the 64bit version)
/x86/sqljdbc_auth.dll (the 32 bit version)
并使用
java -Djava.library.path=.\%PROCESSOR_ARCHITECTURE%\ -jar /my/classpath/goes/here MainClass
在库路径设置中,安装的绝对路径可能是个好主意.
Absolute Path to your install might be a good idea in library-path setting.
解决针对64位主机上的32位Java的上述问题
Helper-Class:Architecture.java
Helper-Class: Architecture.java
public class Architecture {
public static void main(String[] args) {
System.out.print(System.getProperty("os.arch"));
}
}
CMD启动程序
@ECHO OFF
for /f %%i in ('java -classpath /my/classpath/goes/here/ Architecture') do set JAVA_ARCH=%%i
java -Djava.library.path=path/to/dlls/%JAVA_ARCH%/ -cp /my/classpath/goes/here MainClass
您必须像这样命名目录,以匹配可能的os.arch值:
You'd have to name your directories like this to match possible os.arch values:
/x86 - 32 bit DLL goes here
/amd64 - 64 bit DLL goes here
我想,如果您知道这些库的路径,甚至可以在运行MainClass
时根据os.arch
系统属性附加该路径.
I guess if you'd know the path for the libraries you could even append that path based on os.arch
System property at runtime of MainClass
.
这篇关于在32位和64位环境中具有Windows身份验证的SQLServer连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!