0
votes

How may I serve two assets folder for the same URI in Dropwizard. Currently only the first one is being served, when using the same name for URI.

I'm registering AssetsBundle using (in my main application class):

public void initialize(Bootstrap<DummyFrontendConfiguration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/assets1", "/public", null, "assets1"));
    bootstrap.addBundle(new AssetsBundle("/assets2", "/public", null, "assets2"));
    bootstrap.addBundle(new ViewBundle());
}

Css file (main.css) in assets1:

h2{
    color: red;
} 

Css file (main2.css) in assets2:

h4{
    color: green;
}

In html template head:

<link rel="stylesheet" type="text/css" href="public/stylesheets/main.css">
<link rel="stylesheet" type="text/css" href="public/stylesheets/main2.css">

In html template body:

<h2>This should be red</h2>
<h4>This should be green</h4>

Unfortunately the second css file (main2.css) couldn't be loaded during the html page rendering (404 - not found), any ideas?

1
Thank you @condit for the explanation. It is clear now. - Michal Kozon

1 Answers

0
votes

The assets module isn't designed to function this way. Under the hood it's calling:

environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*');

Both servlets can't be mapped to the same path. You could fix this by switching one of the "public" mappings to be another path ("public2", for instance).

If you indeed need to keep your resources completely separate you may want to consider introducing another step in your build (via maven or ant) that merges the assets into a single directory structure for deployment.