使用“G:\ Orchid \ OrchidFX.jar”在cmd中启动jar文件会产生此错误。通过IntelliJ启动应用程序时,一切运行正常。此外,在File-> ProjectStructure中,我们已将sqljdbc4.jar添加到库中。
错误:
javafx.fxml.LoadException:
file:/G:/Orchid/OrchidFX.jar!/DatabaseSettingsForm.fxml
at javafx.fxml.FXMLLoader.constructLoadException(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.loadImpl(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at fxproject.ApplicationSplashScreen.loadDatabaseScreen(ApplicationSplashScreen.java:35)
at fxproject.ApplicationSplashScreen.start(ApplicationSplashScreen.java:26)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.reflect.misc.Trampoline.invoke(Unknown Source)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
... 19 more
Caused by: java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLServerDataSource
at fxproject.OrchidDataSource.setDataSourceSettings(OrchidDataSource.java:56)
at fxproject.OrchidDataSource.<init>(OrchidDataSource.java:50)
at DataSettingsController.initialize(DataSettingsController.java:34)
... 28 more
Caused by: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDataSource
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 31 more
OrchidDataSource.java:
package fxproject;
import java.sql.*;
import com.microsoft.sqlserver.jdbc.*;
public class OrchidDataSource
{
private final String driverType = "jdbc";
private final String dbmsType = "sqlserver";
private String hostname = "192.168.1.173";
private int portNumber = 1433;
private String databaseName = "OrchidDB";
private final String propertyValue = "user=Blah;password=blahblah";
private String username = "blah"; //andrew
private String password = "password";
public String getHostname()
{
return hostname;
}
public int getPortNumber()
{
return portNumber;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
public String getDatabaseName()
{
return databaseName;
}
private SQLServerDataSource dataSource;
private static OrchidDataSource orchidDataSource;
public OrchidDataSource()
{
setDataSourceSettings();
setCurrentDataSource(this);
}
private void setDataSourceSettings()
{
dataSource = new SQLServerDataSource();
dataSource.setUser(username);
dataSource.setPassword(password);
dataSource.setServerName(hostname);
dataSource.setPortNumber(portNumber);
dataSource.setDatabaseName(databaseName);
}
public void setDataSourceSettings(String username, String password, String hostname, int portNumber, String databaseName)
{
this.username = username;
this.password = password;
this.hostname = hostname;
this.portNumber = portNumber;
this.databaseName = databaseName;
setDataSourceSettings();
}
public void setCurrentDataSource(OrchidDataSource orchidDataSource)
{
this.orchidDataSource = orchidDataSource;
}
public static OrchidDataSource getCurrentDataSource()
{
return orchidDataSource;
}
public Connection getConnection() throws SQLException
{
return dataSource.getConnection();
}
}
DataSettingsController:
package fxproject;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.sql.Connection;
public class DataSettingsController
{
public static final String VIEWCONTROLLER_TITLE= "DataSettings";
@FXML
TextField fieldhostname;
@FXML
TextField fieldportnumber;
@FXML
TextField fielddatabasename;
@FXML
TextField fieldusername;
@FXML
PasswordField fieldpassword;
public DataSettingsController()
{
}
@FXML
public void initialize()
{
OrchidDataSource dataSource = new OrchidDataSource();
fieldhostname.setText(dataSource.getHostname());
fieldportnumber.setText(String.valueOf(dataSource.getPortNumber()));
fielddatabasename.setText(dataSource.getDatabaseName());
fieldusername.setText(dataSource.getUsername());
fieldpassword.setText(dataSource.getPassword());
}
@FXML
protected void handleButtonSubmit(ActionEvent e)
{
try
{
OrchidDataSource dataSource = new OrchidDataSource();
dataSource.setDataSourceSettings(fieldusername.getText(),
fieldpassword.getText(),
fieldhostname.getText(),
Integer.parseInt(fieldportnumber.getText()),
fielddatabasename.getText());
Connection connection = OrchidDataSource.getCurrentDataSource().getConnection();
connection.prepareStatement("{call SelectClientStatus()}").executeQuery(); ///low data query to test connection
new MainSystem();
Node source = (Node) e.getSource();
Stage stage = (Stage) source.getScene().getWindow();
stage.close();
}
catch(Exception ae)
{
new OrchidAlertBox("Error", "Database cannot be reached.");
}
}
}