Could someone please help. I have read you recommendation but not able to understand that. I have to read one json file in cloudhub.
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";
OR private static final String jsonFilePath = "input.json";
When .json
file is in root folder of project
byte[] jsonFile = Files.readAllBytes(Paths.get(jsonFilePath));
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.
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 05/26/2015 INFO file:/home/ion-mule/muleProperties.dump
21:53:30.952 05/26/2015 INFO file:/home/ion-mule/muleLauncher.log
21:53:30.953 05/26/2015 INFO directory:/home/ion-mule/.ssh
21:53:30.953 05/26/2015 INFO file:/home/ion-mule/.bash_profile
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/.ssh/authorized_keys
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/.bash_logout
21:53:30.954 05/26/2015 INFO file:/home/ion-mule/muleMonitor.log
21:53:30.955 05/26/2015 INFO file:/home/ion-mule/.bashrc
Any help will be appreciated.
You need to load your application resources from the classpath, not from a path that is related to the original project structure.
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");
来源:https://stackoverflow.com/questions/30497880/mule-unable-to-locate-json-file-when-deployable-archive-move-to-cloudhub