0

This error is produced by launching the jar file in cmd with "G:\Orchid\OrchidFX.jar". When launching the application through IntelliJ everything runs just fine. Also, in File->ProjectStructure we have added sqljdbc4.jar to the library.

The Error:

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.");
        }
    }
}
5
  • 2
    You also need to provide the jdbc jar when you launch your program from the command line. How are you launching your program at the command line? Commented Apr 16, 2016 at 4:38
  • To add onto @ElliottFrisch's comment, IntelliJ is most likely setting a classpath for you when it runs, and this classpath contains the sqlserver driver jar file. Intellij prints the entire java command that it invokes as the very first line of output when you run it, so you can use that to figure out how to set your classpath. Commented Apr 16, 2016 at 4:41
  • @ElliottFrisch , I just type G:\Orchid\OrchidFX.jar into the command line to launch it. What should I be typing instead? Commented Apr 16, 2016 at 13:53
  • I noticed I accidentally linked to this same post in my earlier comment (now deleted). Meant to link here: stackoverflow.com/questions/22253551/… Commented Apr 16, 2016 at 16:35
  • @Roman I modified the manifest to Main-Class: fxproject.ApplicationSplashScreen Class-Path: C:\Program Files\Java\jdk1.8.0_73 and now when I load the jar, nothing launches. Commented Apr 16, 2016 at 17:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.