首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在docker容器中引用java maven项目中的资源文件

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

Stack Overflow用户
提问于 2019-01-09 23:16:11
回答 1查看 1.3K关注 0票数 1

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

对于身份验证,我需要一个文件zoho-oauthtokens.properties,它位于src/main/resources中,我从另一个名为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. Caused by : com.zoho.oauth.common.ZohoOAuthException. Caused by : java.io.FileNotFoundException: src/main/resources/zoho-oauthtokens.properties (No such file or directory)

那么,我如何正确地引用资源文件,以便在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

EN

回答 1

Stack Overflow用户

发布于 2020-03-18 09:47:18

你试过了吗?

代码语言:javascript
复制
oauth_tokens_file_path=classpath*:zoho-oauthtokens.properties

因为它在不同的罐子里。同样,我不确定zoho-oauthtokens.properties是如何加载到代码中的。值得一试。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54113212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档