简体   繁体   中英

Serve static files from Java webapp subdirectory

I have a Java webapp (RESTEasy) organized as follows:

src/main
  |- java/
  |- webapp/
    |- WEB-INF/
      |- web.xml
    |- public/
      |- <compiled static files>

The public folder gets filled with static files (index.html, compiled js, css and resources) by my build chain. When building the WAR archive, I can access the static files under /public/index.html .

Is there a way to serve my static files directly from the root ( /index.html )? I know that I can directly put them in my webapp folder, however due to my build chain and project structure, I would like to avoid this.

Normally, containers allow you to specify the document root. It means you can have the web application like structure where ever you want. But, you cannot have something like what you want. Since, it is not Web application structure.

Some containers also allow you to specify the documents base. Like Tomcat for Ex,You can specify this in the server.xml

<Context docBase="/path/to/files" path="/files" />

One workaround is adding a filter that will prepend "public" to all the urls.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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