fwind
fwind

Reputation: 1314

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.

Upvotes: 0

Views: 965

Answers (1)

Ramesh PVK
Ramesh PVK

Reputation: 15446

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.

Upvotes: 1

Related Questions