仅在发布模式下启动服务器时出现错误(使用使用ANT构建的jar文件)
我附加了一个带有realease-run和IDE-run(使用IntelliJ)的图像。我不知道该怎么做,我尝试了一切,问这是我最后的机会。
出现错误的代码部分是:
//[sqlmanager side] SQLManager.java:
public SQLManager(ServerLogger slogg)
{
logger = slogg;
try {
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres",
"postgres", "123");
logger.Write("SQL Manager - connection enstablished 2/2");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getClass().getName() + ": " + e.getMessage());
logger.Write("Errore Connessione SQL (SQL context)");
}
}
//[server side] Server.java
private void init_SQL_Database() {
try {
logger_pane.Write("SQL Manager - initing connection 1/2");
sqlmanager = new SQLManager(logger_pane);
} catch (Exception ex) {
Logger.getLogger(serSchoolLib.class.getName()).log(Level.SEVERE, null, ex);
logger_pane.Write("* Errore Connessione SQL (server context)");
}
}
这是一个例外:
java.lang.ClassNotFoundException: org.postgresql.Driver
18:17] java.net.URLClassLoader.findClass(Unknown Source)
[18:17] java.lang.ClassLoader.loadClass(Unknown Source)
[18:17] sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[18:17] java.lang.ClassLoader.loadClass(Unknown Source)
[18:17] java.lang.Class.forName0(Native Method)
[18:17] java.lang.Class.forName(Unknown Source)
[18:17] Server.SQLManager.<init>(Unknown Source)
[18:17] Server.serSchoolLib.init_SQL_Database(Unknown Source)
[18:17] Server.serSchoolLib.start(Unknown Source)
[18:17] Server.ServerLogger.OKButtonActionPerformed(ServerLogger.java:278)
[18:17] Server.ServerLogger.access$000(ServerLogger.java:22)
[18:17] Server.ServerLogger$1.actionPerformed(ServerLogger.java:93)
[18:17] javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
[18:17] javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
[18:17] javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
[18:17] javax.swing.DefaultButtonModel.setPressed(Unknown Source)
[18:17] javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
[18:17] java.awt.Component.processMouseEvent(Unknown Source)
[18:17] javax.swing.JComponent.processMouseEvent(Unknown Source)
[18:17] java.awt.Component.processEvent(Unknown Source)
[18:17] java.awt.Container.processEvent(Unknown Source)
[18:17] java.awt.Component.dispatchEventImpl(Unknown Source)
[18:17] java.awt.Container.dispatchEventImpl(Unknown Source)
[18:17] java.awt.Component.dispatchEvent(Unknown Source)
[18:17] java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
[18:17] java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
[18:17] java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
[18:17] java.awt.Container.dispatchEventImpl(Unknown Source)
[18:17] java.awt.Window.dispatchEventImpl(Unknown Source)
[18:17] java.awt.Component.dispatchEvent(Unknown Source)
[18:17] java.awt.EventQueue.dispatchEventImpl(Unknown Source)
[18:17] java.awt.EventQueue.access$500(Unknown Source)
[18:17] java.awt.EventQueue$3.run(Unknown Source)
[18:17] java.awt.EventQueue$3.run(Unknown Source)
[18:17] java.security.AccessController.doPrivileged(Native Method)
[18:17] java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
[18:17] java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
[18:17] java.awt.EventQueue$4.run(Unknown Source)
[18:17] java.awt.EventQueue$4.run(Unknown Source)
[18:17] java.security.AccessController.doPrivileged(Native Method)
[18:17] java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
[18:17] java.awt.EventQueue.dispatchEvent(Unknown Source)
[18:17] java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
[18:17] java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
[18:17] java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
[18:17] java.awt.EventDispatchThread.pumpEvents(Unknown Source)
[18:17] java.awt.EventDispatchThread.pumpEvents(Unknown Source)
[18:17] java.awt.EventDispatchThread.run(Unknown Source)
on the left -> Release Running (with error) | on the right -> running from IDE
答案 0 :(得分:0)
从ANT构建的 .jar 文件运行程序时遇到的问题是,您没有包含PostgreSQL JDBC驱动程序来构建 *。jar 文件。 您应该能够在运行程序时引用驱动程序类的静态和动态引用,在您的情况下,不会发生对驱动程序类的动态引用 - 因为它不是您正在运行的jar文件的一部分(或者,当您运行程序时,并不是指PostgreSQL JDBC驱动程序。
您需要运行程序,添加对驱动程序jar的必要引用,并且应该解决您已报告的此问题。