1. 程式人生 > >【錯誤解決】[Maven] cannot be opened because it does not exist錯誤[檔案無法編譯到target目錄下的解決方法]

【錯誤解決】[Maven] cannot be opened because it does not exist錯誤[檔案無法編譯到target目錄下的解決方法]

使用IDEA搭建的Maven專案,在寫SpringEL和資源呼叫時出現瞭如下錯誤:
相信我,程式碼沒問題的、

Caused by: java.io.FileNotFoundException: class path resource [cn/hncu/p2_2_2SpringEL/test.properties] cannot be opened because it does not exist

檔案無法找到,後來在csdn論壇提問後才知道。

因為IDEA有個配置項,預設只把.class的檔案放到編譯目錄中,也就是target目錄。

後來我去看了target目錄下,確實沒有那檔案。

我的Java目錄下是有的:

找到了問題所在,就好辦了.

開始我想重新去改一下IDEA的配置。但是沒找到怎麼改。

現在先說下用程式碼配置、
原因是: idea不會編譯src的java目錄的除Java外的檔案

解決辦法:

將IDEA maven專案中src原始碼下的資原始檔編譯進target目錄classes資料夾
具體操作方法就是:配置maven的pom檔案配置,在<build>節點下新增<resources>程式碼:

也就是:

<build>
        <resources>
            <resource
>
<directory>src/main/java</directory> <includes> <include>**/*.*</include> </includes> <excludes> <exclude>**/*.java</exclude> </excludes
>
</resource> </resources> </build>

這樣就是把除.java外的src下的檔案,自動編譯到target目錄classes資料夾下!

問題解決!

因為是剛用IDEA,也不知道怎麼去IDEA配置編譯其他檔案到target目錄,也不知道是不是IDEA不支援自動拷貝其他型別的檔案到target目錄。

如果有朋友知道,望在評論區解答,謝謝。

Eclipse是在build path裡配置的:

本文章由[諳憶]編寫, 所有權利保留。