简体   繁体   English

发布时找不到资源束

[英]Can't find Resource Bundle at release time

I have a multi-module Maven project that looks like this: 我有一个如下所示的多模块Maven项目:

reactor
 | core
 | console
 | custom-maven-plugin (depends on core)
 | test-deployment

I have a resource bundle with the base name login which I exclude from Git, because it contains passwords. 我有一个基本名称为login的资源包,该资源包已从Git中排除,因为它包含密码。 In my project, the file is located in core/src/test/resources and I have a test class, which uses it like so: 在我的项目中,该文件位于core/src/test/resources并且我有一个测试类,该类的用法如下:

public abstract class TestBase {
    private static final ResourceBundle constants = ResourceBundle.getBundle("constants");
    private static final ResourceBundle bundle = ResourceBundle.getBundle("login");
    private Connection connection;

    // ...

    Connection getConnection() {
        // Connection will be created in another method, this one just returns it.
    }
}

public class ActualTest extends TestBase {
    // Uses the connection in tests here.
}

Now if I execute mvn package for the whole project, the tests all finish correctly. 现在,如果我对整个项目执行mvn package ,则所有测试均正确完成。

On my build server, I have a script which creates the login.properties , since it's not included in the cloned project: 在我的构建服务器上,我有一个脚本可以创建login.properties ,因为它不包含在克隆的项目中:

printf "userName=$bamboo_login_userName\npassword=$bamboo_login_password" > core/src/test/resources/login.properties

The build server executed mvn clean release:prepare release:perform , but at this point, the build fails to this exception: 生成服务器执行了mvn clean release:prepare release:perform ,但是在这一点上,生成未能出现以下异常:

java.util.MissingResourceException: Can't find bundle for base name login, locale en_US

I already checked the directory core/src/test/resources and core/target/test-classes , but the file is there. 我已经检查了目录core/src/test/resources core/target/test-classes ,但是文件在那里。 For some reason, the resource bundle for constants doesn't throw an exception, which tells me, there is a problem with how I create that login file. 出于某种原因, constants的资源束不会引发异常,这告诉我,如何创建该登录文件存在问题。

Is there any explanation for this behaviour? 有这种行为的任何解释吗?

您是否应该在main而不是test生成您的login.properties?

printf "userName=$bamboo_login_userName\npassword=$bamboo_login_password" > core/src/main/resources/login.properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM