簡體   English   中英

將Java項目導出為JAR,並嘗試在ECLIPSE的動態Web項目中使用它后,找不到資源文件

[英]Cannot find a resource file, after exporting java project as JAR, and trying to use it in a Dynamic Web Project in ECLIPSE

我有一個工作的Java程序,它正在使用derby進行一些數據庫工作。 用於連接的數據庫URL

JDBC:德比://本地主機:1527 / MaorB_CouponDB

不是硬編碼 ,而是寫入.txt文件(位於“文件”文件夾中,而不是src)中。 運行項目並像這樣測試系統非常完美。

該項目的第二階段正在全部轉移到Web上,該java程序充當服務器上執行DB動作的大腦。 我將整個項目導出為.JAR,並且可以看到它還包含“文件”文件夾(帶有url txt和其他文件)。

但是,嘗試運行一個簡單的測試以在新的Dynamic Web Project上進行檢查(在將project.jar,derby_client.jar作為外部庫導入之后)會導致異常:

ERROR: something went wrong. cannot initialize a ConnectionPool instance. cause:
URL file not found, on connection pool CTOR
x.exceptions.ConnectionPoolException: URL file not found, on connection pool CTOR
    at b.connections.ConnectionPool.<init>(ConnectionPool.java:34)
    at b.connections.ConnectionPool.getInstance(ConnectionPool.java:73)
    at d.DAO.CompanyDbDAO.<init>(CompanyDbDAO.java:26)
    at f.system.CouponSystem.<init>(CouponSystem.java:36)
    at f.system.CouponSystem.getInstance(CouponSystem.java:58)
    at a.test.main(test.java:11)
Caused by: java.io.FileNotFoundException: files\urlFile (The system cannot find the path specified)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(Unknown Source)
    at java.io.FileInputStream.<init>(Unknown Source)
    at java.util.Scanner.<init>(Unknown Source)
    at b.connections.ConnectionPool.<init>(ConnectionPool.java:31)
    ... 5 more

手動將.txt文件復制到新的Web項目中的多個位置不會產生任何結果。

在這里和其他地方進行的快速研究建議以某種方式使用:

this.getClass().getResourceAsStream("/files/urlFile.txt");

但是在嘗試使用路徑字符串進行很多變體后,我只會得到null。

有什么建議么? 謝謝。


編輯:這是我嘗試過的所有事情,我認為是相關的: 嘗試獲取資源時導致null


EDIT2: inputstream為null,txt在src / newfiles /下

確保資源文件在結果jar中。 這通常是此類錯誤的原因。 如果發布構建文件,將更容易獲得幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM