I have a JavaEE application deployed on Wildfly and running correctly on both Ubuntu and Windows OS. However, when I try to Dockerized the application it fails.
Here is the part of the code that fails:
File templateFile = new File(ESGenerator.class.getClassLoader().getResource("/endpoint-js-template/get-template.js").getFile());
// ...
endpointJSInterface.setTemplate(FileUtils.readFileToString(templateFile));
Here are the file location when I tried to log:
// Ok - Ubuntu /home/czetsuya/java/jboss/wildfly-15.0.1.Final/standalone/deployments/myApp.war/WEB-INF/lib/myApp-admin-ejbs-6.9.0-SNAPSHOT.jar/endpoint-js-template/get-template.js
// Ok - Windows c:\Java\Jboss\wildfly-15.0.1.Final\standalone\deployments\myApp.war\WEB-INF\lib\myApp-admin-ejbs-6.9.0-SNAPSHOT.jar\endpoint-js-template\get-template.js
// Ko - Docker /content/myApp.war/WEB-INF/lib/myApp-admin-ejbs-6.9.0-SNAPSHOT.jar/endpoint-js-template/get-template.js
Where does '/content' comes from and what's the best way to solve this issue?
The solution would be to avoid using new File operation.
Here's how I fix this issue.
// get the URL of the resource from the jar file
URL templateUrl = ESGenerator.class.getClassLoader().getResource("/endpoint-js-template/get-template.js");
// load as string using IOUtils
endpointJSInterface.setTemplate(IOUtils.toString(templateUrl));