无法访问将类路径发布为 webApp 的 tomee 嵌入式应用程序中的静态 html 资源

Cannot access static html resources in a tomee-embedded application that publishes classpath as webApp

我正在尝试在应用程序中配置 tomee-embedded。所有 classes 和 html 文件都在同一个 gradle 项目中,因此 tomee-embeddedclasspath 作为 webApp.

我可以验证 EJB 和 Servlet 以及 web 服务是否正常工作。

但是,/src/webapp 中的 html 静态资源似乎没有提供。 例如,我无法访问 /src/webapp/index.html 中的 index.html,也无法访问任何其他文件和文件夹。

我尝试了一些方法,如下所示。

出于完整性原因,我使用的 gradle 导入如下:

  implementation 'org.apache.tomee:tomee-embedded:8.0.6'

如何让 tomee-embedded 也为 index.htmlsrc/webapp 文件夹下的其他资源提供服务?

我终于弄明白了。 当 运行 gradle 应用程序插件的“运行”任务时,以下将起作用。

   public final class Main {

   public static final void main(final String[] args) {
    
    final Configuration configuration=new Configuration();
    configuration.setHttpPort(8082);
    try (final Container container = new Container(configuration)) {

        //Works in gradle application:run
        final File docbase=new File("src/main/webapp");
        System.out.println("Docbase:"+docbase.getAbsolutePath());
        container.deployClasspathAsWebApp("/",docbase,true);
        System.out.println("Started on http://localhost:" + container.getConfiguration().getHttpPort());

        container.await();
    } catch (final Exception exception) {
        LOGGER.error(ExceptionUtils.getStackTrace(exception));
    }
    }
    }

文档库应指向 webapp 文件夹的确切位置。 这意味着在实际的实施分发中,相对 src/main/webapp 应该替换为实际的 webapp 文件夹位置。