ule子:当可部署档案移至CloudHub时,无法找到.json文件 [英] Mule: Unable to locate .json file when Deployable archive move to CloudHub
问题描述
请有人帮忙.我已经阅读了您的建议,但无法理解.我必须在cloudhub中读取一个json文件.
Could someone please help. I have read you recommendation but not able to understand that. I have to read one json file in cloudhub.
在我的本地存储库中,我已将.json文件保存在位置test/src/main/resources/input.json
中.并从Java类中阅读
In my local repositories I have kept the .json file in location test/src/main/resources/input.json
. And reading this from Java Class
private static final String jsonFilePath = "src\main\resources\input.json";
private static final String jsonFilePath = "src\main\resources\input.json";
或 private static final String jsonFilePath = "input.json";
OR private static final String jsonFilePath = "input.json";
.json
文件位于项目的根文件夹中时
When .json
file is in root folder of project
byte[] jsonFile = Files.readAllBytes(Paths.get(jsonFilePath));
当MDA moved to cloud hub
时找不到"input.json
"文件,并且我在cloudhub
中发现文件未找到异常.当我将所有文件打印到项目目录中时,我无法从cloudHub中的项目中搜索任何特定文件.
Not able to find the "input.json
" file when MDA moved to cloud hub
and I am getting file not found exception in cloudhub
. when I printed all my files in my project directory, I am not able to search any specific files from my project in cloudHub.
我已经在cloudHub的项目目录结构中打印了所有文件,但是找不到"input.json
".您能提出建议吗?
I have printed all files in my project directory structure in cloudHub but I not able to find "input.json
". Could you please suggest.
21:53:30.952 2015/05/26信息文件:/home/ion-mule/muleProperties.dump
21:53:30.952 05/26/2015 INFO file:/home/ion-mule/muleProperties.dump
21:53:30.952 2015/05/26信息文件:/home/ion-mule/muleLauncher.log
21:53:30.952 05/26/2015 INFO file:/home/ion-mule/muleLauncher.log
21:53:30.953 2015/05/26信息目录:/home/ion-mule/.ssh
21:53:30.953 05/26/2015 INFO directory:/home/ion-mule/.ssh
21:53:30.953 2015年5月26日INFO文件:/home/ion-mule/.bash_profile
21:53:30.953 05/26/2015 INFO file:/home/ion-mule/.bash_profile
21:53:30.954 05/26/2015 INFO文件:/home/ion-mule/.ssh/authorized_keys
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/.ssh/authorized_keys
21:53:30.954 05/26/2015 INFO文件:/home/ion-mule/.bash_logout
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/.bash_logout
21:53:30.954 05/26/2015 INFO文件:/home/ion-mule/muleMonitor.log
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/muleMonitor.log
21:53:30.955 2015/05/26信息文件:/home/ion-mule/.bashrc
21:53:30.955 05/26/2015 INFO file:/home/ion-mule/.bashrc
任何帮助将不胜感激.
推荐答案
您需要从类路径而不是与原始项目结构相关的路径中加载应用程序资源.
You need to load your application resources from the classpath, not from a path that is related to the original project structure.
src\main\resources
中的文件最终位于打包应用程序中类路径的根目录.因此,以下内容应以流的形式为您提供文件的内容:
Files in src\main\resources
end-up at the root of the classpath in the packaged application. So the following should provide you with the file's content as a stream:
Thread.currentThread().getContextClassLoader().getResourceAsStream("input.json");
这篇关于ule子:当可部署档案移至CloudHub时,无法找到.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!