简体   繁体   English

如何使用 thorntail 提供 static 内容

[英]How do I serve static content with thorntail

I have a new project created using the Thorntail Project Generator .我有一个使用Thorntail Project Generator创建的新项目。 I want to serve a small amount of static files such as html, images etc我想提供少量 static 文件,例如 html、图像等

How can I do this?我怎样才能做到这一点?

Assuming you build your project with Maven, you need to:假设您使用 Maven 构建项目,您需要:

  • make sure that your Maven project is <packaging>war</packaging>确保您的 Maven 项目是<packaging>war</packaging>
  • add a dependency on the io.thorntail:undertow fraction添加对io.thorntail:undertow分数的依赖项
  • put your static content into src/main/webapp (but not under src/main/webapp/WEB-INF )将您的 static 内容放入src/main/webapp (但不在src/main/webapp/WEB-INF下)
  • if you also use JAX-RS, make sure that the JAX-RS application is not bound to / ;如果您还使用 JAX-RS,请确保 JAX-RS 应用程序未绑定到/ for example, if you use the most common way of enabling JAX-RS (creating an Application subclass with the @ApplicationPath annotation), make sure that you don't have @ApplicationPath("/") , but something like @ApplicationPath("/api")例如,如果您使用启用 JAX-RS 的最常见方式(使用@ApplicationPath注释创建Application子类),请确保您没有@ApplicationPath("/") ,而是类似@ApplicationPath("/api")

I created a small example project here: https://github.com/rhoar-qe/thorntail-test-suite/tree/master/javaee/static-content我在这里创建了一个小示例项目: https://github.com/rhoar-qe/thorntail-test-suite/tree/master/javaee/static-content

Note that Thorntail is based on WildFly, and so includes the same servlet container: Undertow.请注意,Thorntail 基于 WildFly,因此包含相同的 servlet 容器:Undertow。 If you have more elaborate needs, you can find articles about serving static content with servlet in general and Undertow in particular everywhere on the web, including here on StackOverflow.如果您有更详细的需求,您可以在 web 上找到有关使用 servlet 提供 static 内容的文章,尤其是在 Undertow 的任何地方,包括在 StackOverflow 上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM