似乎有许多与此相关的类似问题,但没有一个能够为我提供任何帮助。我在SQL Server (我正在使用)上运行Microsoft 的 JDBC 驱动程序,并使用集成身份验证来访问我的数据库。连接的代码片段如下:sqljdbc4.jar
String connectionUrl="jdbc:sqlserver://servername:1433;integratedSecurity=true;";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
}//catch, etc...
当我在Eclipse中运行该项目时,它可以顺利启动。但是,当我运行Maven全新安装并将其打包到 .jar 中时,出现错误:
java.lang.ClassNotFoundException: Failure to load: com.microsoft.sqlserver.jdbc.SQLServerDriver
at launch.JarClassLoader.loadClass(JarClassLoader.java:964)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ui.SearchWindow$1.run(SearchWindow.java:97)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
我尝试了其他线程中发布的解决方案;我有一个CLASSPATH
指向 的系统变量,.jar
它位于我的构建路径和运行时类路径中。也许问题就在我眼前。我最好的猜测是它与 Maven 有关,但我应该如何解决这个问题?
另外,如果我需要澄清任何问题,请告诉我;我很乐意这样做。