gpt4 book ai didi

java - 如何在docker容器中运行的java maven项目中引用资源文件

转载 作者:太空宇宙 更新时间:2023-11-04 09:56:14 24 4
gpt4 key购买 nike

我正在尝试在 docker 容器中运行 java maven (spring boot) 项目来访问 zoho api。

对于身份验证,我需要一个位于 src/main/resources 中的文件 zoho-oauthtokens.properties,我从另一个名为 oauth_configuration.properties 的属性文件引用该文件,如下所示:oauth_tokens_file_path=src/main/resources/zoho-oauthtokens.properties

只要我在 Eclipse 中将应用程序作为 Spring 应用程序运行,一切都会正常工作,但是一旦我在 docker 容器中运行它,我就会得到:com.zoho.crm.library.exception.ZCRMException com.zoho.oauth.common.ZohoOAuthException。引起的原因:com.zoho.oauth.common.ZohoOAuthException。引起:java.io.FileNotFoundException:src/main/resources/zoho-oauthtokens.properties(没有这样的文件或目录)

那么如何正确引用资源文件,以便在 Docker 容器中运行它时也能找到它?有什么想法吗?

我尝试过:

oauth_tokens_file_path=src/main/resources/zoho-oauthtokens.properties

oauth_tokens_file_path=classpath:/zoho-oauthtokens.properties

oauth_tokens_file_path=/zoho-oauthtokens.properties

oauth_tokens_file_path=zoho-oauthtokens.properties

并将其放入我的项目的根文件夹后:oauth_tokens_file_path=/zoho-oauthtokens.properties

oauth_tokens_file_path=zoho-oauthtokens.properties

最好,尼尔斯

编辑:它尝试了更多选项:

../../../zoho-oauthtokens.properties

./zoho-oauthtokens.properties

/BOOT-INF/classes/zoho-oauthtokens.properties

BOOT-INF/classes/zoho-oauthtokens.properties

我还检查了 Maven 构建后的 jar 文件。这是相关文件所在的位置:

BOOT-INF/classes/de/xxx/xxx/Application.class

BOOT-INF/classes/zoho-oauthtokens.properties

BOOT-INF/classes/oauth_configuration.properties

最佳答案

你试过吗

oauth_tokens_file_path=classpath*:zoho-oauthtokens.properties

因为它在不同的 jar 里。我再次不确定 zoho-oauthtokens.properties 如何在代码中加载。值得一试。

关于java - 如何在docker容器中运行的java maven项目中引用资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54113212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com