[英]MissingResourceException: Can't find bundle for base name when running JAR
I made a maven spring-boot project using Spring Initializr and added the basic dependencies like starter-web, tom-cat-jasper, dev-tools and etc.. then imported it in Eclipse. I made a maven spring-boot project using Spring Initializr and added the basic dependencies like starter-web, tom-cat-jasper, dev-tools and etc.. then imported it in Eclipse.
I then added a new external JAR in my local repository that is not from maven repository using然后我在我的本地存储库中添加了一个新的外部 JAR 不是来自 maven 存储库使用
mvn install:install-file
and added the new dependendcy in the pom.xml并在 pom.xml 中添加了新的依赖项
<dependency>
<groupId>com.domain.project</groupId>
<artifactId>resourceName</artifactId>
<version>1</version>
</dependency>
And this external JAR has a.properties that's need to be added in order for it to connect to a database.这个外部 JAR 有一个需要添加的属性才能连接到数据库。 I put this.properties file in src/main/resources and tested the methods in the external JAR and it works as intended in the Eclipse IDE.
我将 this.properties 文件放在src/main/resources中并测试了外部 JAR 中的方法,它按 Eclipse Z581D6381F3F35E4F96D77201ACF87B 中的预期工作。
After this I run the project as Maven build with goals: clean install
so that it can be run as an executable JAR.在此之后,我将项目运行为 Maven 构建目标:全新
clean install
,以便它可以作为可执行文件 JAR 运行。
Then I run the JAR with start java -jar
using a.bat file everything is working but whenever I used the methods from the external JAR via GET/POST request it gives the error:然后我运行 JAR 并使用 a.bat 文件
start java -jar
一切正常,但每当我使用来自外部 JAR 的方法时,它通过 GET/POST 请求给出错误:
java.util.MissingResourceException: Can't find bundle for base name resourceName, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1581) ~[?:1.8.0_241]
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1396) ~[?:1.8.0_241]
at java.util.ResourceBundle.getBundle(ResourceBundle.java:782) ~[?:1.8.0_241]
at com.domain.project.vitality.VitalityInfo.VitalityInfoDetails(VitalityInfo.java:28) ~[resourceName-1.jar!/:?]
This is the name of the external JAR: resourceName.jar and the required properties file: resourceName.properties.这是外部 JAR 的名称:resourceName.jar 和所需的属性文件:resourceName.properties。
I also encountered this error if I rename or removed the required.properties file in src/main/resources in Eclipse IDE.如果我在 Eclipse IDE 的src/main/resources中重命名或删除 required.properties 文件,我也会遇到此错误。
If I run the project only in Eclipse IDE and access the said external JAR methods via GET/POST request it gives the usual JDBC SQL error. If I run the project only in Eclipse IDE and access the said external JAR methods via GET/POST request it gives the usual JDBC SQL error.
How do I fix this whenver I build using maven any help is very much appreciated?每当我使用 maven 构建时,我该如何解决这个问题,非常感谢任何帮助?
EDIT: This is the result from jar tf
of executable JAR when using maven build.编辑:这是使用 maven 构建时可执行 JAR 的
jar tf
的结果。
BOOT-INF/classes/application.properties
BOOT-INF/classes/resourceName.properties
BOOT-INF/classes/log4j2-spring.xml
EDIT: Issue is resolved.编辑:问题已解决。
Turns out the solution was rather simple.原来解决方案相当简单。
In my case the external JAR has this in its implementation在我的情况下,外部 JAR 在其实现中具有此功能
ResourceBundle bundle = ResourceBundle.getBundle("resourceName");
I changed this into我把它改成了
ResourceBundle bundle = ResourceBundle.getBundle("application");
And simply renamed resourceName.properties file into application.properties or just copy the content from resourceName.properties into your application.properties or any property file that spring-boot is able to read.只需将 resourceName.properties 文件重命名为 application.properties 或将 resourceName.properties 中的内容复制到您的 application.properties 或 spring-boot 能够读取的任何属性文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.