【问题标题】:Classloader getResource failed when running Wildfly inside Docker在 Docker 中运行 Wildfly 时,类加载器 getResource 失败
【发布时间】:2020-05-29 07:15:04
【问题描述】:

我在 Wildfly 上部署了一个 JavaEE 应用程序,并且在 Ubuntu 和 Windows 操作系统上都能正常运行。但是,当我尝试对应用程序进行 Docker 化时,它失败了。

这是失败的代码部分:

File templateFile = new File(ESGenerator.class.getClassLoader().getResource("/endpoint-js-template/get-template.js").getFile());
// ...
endpointJSInterface.setTemplate(FileUtils.readFileToString(templateFile));

这是我尝试登录时的文件位置:

// 好的 - 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

// 好的 - 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

“/content”从何而来,解决此问题的最佳方法是什么?

【问题讨论】:

    标签: docker wildfly classloader java-ee-6 java-ee-7


    【解决方案1】:

    解决方案是避免使用新的文件操作。

    这是我解决此问题的方法。

    // 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));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-24
      相关资源
      最近更新 更多