我正在尝试使用带有sqlite的maven部署javafx-13项目

时间:2020-06-09 13:47:40

标签: sqlite maven javafx

我使用Maven创建了一个具有DB类的简单Fx项目。 因此,在运行javafx:compiler和javafx:run之后,一切正常! 但是在部署项目之后,并从扩展名为laucher.bat的Windows运行它, 我有例外:java.lang.ClassNotFoundException:org.sqlite.JDBC

DB.java:

package Managment;

import javafx.scene.control.Label;
import java.sql.*;

public class DB {
    public Label label;
    Connection connection;

    public void switchToSecondary(){
        try {
            Class.forName("org.sqlite.JDBC");
            connection = DriverManager.getConnection("jdbc:sqlite:Management.sqlite");
            label.setText("Seccuss");
        }catch (Exception e){
            label.setText(e.toString());
        }

    }
}

这里是pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Managment</groupId>
    <artifactId>javafx</artifactId>
    <version>1.0</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11.0.1</version>
        </dependency>
            <dependency>
            <!--i try many version of sqlite first one is 3.15.1 -->
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.6.14.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <mainClass>Managment.App</mainClass>
                    <launcher>laucher.bat</launcher>
                    <jlinkImageName>M1</jlinkImageName>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

这里是model_info.java:

module Managment {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.sql;

    opens Managment to javafx.fxml;
    exports Managment;
}

我不知道为什么该异常在部署之后出现,在部署之前一切正常:(

0 个答案:

没有答案