当我从IDE(作为Java应用程序)启动时,它运行良好,但是当我部署它(maven native命令)并通过.exe文件启动它时,它甚至无法找到目录。
如果我写'jdbc:sqlite:SeeYourUse.db',问题就解决了,但我认为我应该将所有资源保存在'src / main / resources'下。
顺便说一句,所有图像都正确加载。
有人可以解释问题隐藏在哪里吗?
这是我项目的POM的一部分。基本上,它包含对SQLite的依赖(已下载并正常工作)和JavaFX插件(也可正常工作)
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.2.0</version>
<configuration>
<mainClass>com.SeeYourUse.Main</mainClass>
</configuration>
<dependencies>
<dependency>
<groupId>org.twdata.maven</groupId>
<artifactId>mojo-executor</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.SeeYourUse.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
</dependencies>
<url>https://github.com/CrazzyBeer/SeeYourUse</url>
以下是连接数据库的方法。
private void connect() {
try {
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:src/main/resources/DB/SeeYourUse.db");
} catch (Exception e) {
//System.err.println("Couldn't connect to the DB");
e.printStackTrace();
}
// System.out.println("DB Opened successfully");
}
这是我得到的错误堆栈跟踪
java.sql.SQLException: path to 'src/main/resources/DB/SeeYourUse.db': 'E:\Programming\Java\Work\SeeYourUse\target\jfx\native\SeeYourUse-0.0.1-SNAPSHOT\app\src' does not exist
at org.sqlite.Conn.open(Conn.java:103)
at org.sqlite.Conn.<init>(Conn.java:57)
at org.sqlite.JDBC.createConnection(JDBC.java:77)
at org.sqlite.JDBC.connect(JDBC.java:64)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.SeeYourUse.SQLiteDB.connect(SQLiteDB.java:30)
at com.SeeYourUse.SQLiteDB.createMessages(SQLiteDB.java:111)
at com.SeeYourUse.SQLiteDB.init(SQLiteDB.java:96)
at com.SeeYourUse.Main.start(Main.java:21)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)