【错误解决】[Maven] cannot be opened because it does not exist错误[文件无法编译到target目录下的解决方法]

转载请注明出处:http://blog.csdn.net/qq_26525215

本文源自大学之旅_谙忆的博客

使用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目录下,确实没有那文件。

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
引用\[1\]:在解决"class path resource \[redis.properties\] cannot be opened because it does not exist"的问题时,可以检查以下几个方面。首先,确保你的项目中存在redis.properties文件。如果文件确实存在,那么可能是配置文件的路径不正确导致无法找到。你可以在pom.xml文件中的<build>标签下添加以下配置来指定配置文件的路径: ``` <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> </includes> <filtering>false</filtering> </resource> </resources> ``` 这样配置后,Maven会将src/main/resources目录下的所有.properties文件包括在项目的classpath中,确保可以找到redis.properties文件。如果问题仍然存在,可以尝试重新构建项目并清理缓存。 引用\[2\]:另外,还可以在pom.xml文件中的<build>标签下添加以下配置来确保resources目录下的文件也被包括在项目的classpath中: ``` <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> ``` 这样配置后,resources目录下的所有.properties和.xml文件都会被包括在项目的classpath中。 引用\[3\]:此外,还需要检查各个子项目的默认的字节码文件输出地址。默认情况下,Spring Boot会将字节码文件输出到默认的out文件夹下。建议将输出路径修改为各个子项目的target文件夹下,这样可以更好地管理生成的字节码文件。同时,还需要注意,resources目录下的文件可能不会自动复制到target文件夹中。你可以手动将resources目录下的文件复制到target文件夹中,这样就不会影响本地开发了。target文件夹的层级结构如下: ``` target └── classes └── com └── example └── demo ├── 编译生成的字节码文件 └── properties包(手动复制的配置文件) ``` 通过以上步骤,你应该能够解决"class path resource \[redis.properties\] cannot be opened because it does not exist"的问题。 #### 引用[.reference_title] - *1* [class path resource [config.properties] cannot be opened because it does not exist](https://blog.csdn.net/qidaihuimou/article/details/113779820)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [class path resource [ database.properties] cannot be opened because it does not exist](https://blog.csdn.net/weixin_52675722/article/details/121191862)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [class path resource [db.properties] cannot be opened because it does not exist](https://blog.csdn.net/wwwwwww31311/article/details/130303601)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谙忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值