1

Hi all,

at Can DropWizard serve assets from outside the jar file? I have read, that it is possible to serve static files outside of jar file with dropwizard-configurable-assets-bundle (later only DCAB).

But there are no examples available on the web. The only one, at their github page is not very helpful for me.

Firstly, there is said, that I should implement AssetsBundleConfiguration, but there is no mention where should I use it then.

Next, in service I should put this row: bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/dashboard/")); But unfortunately, it is showing me an error, that it is not applicable for that argument.

And in third part there is some yaml, but I don't know, whether it's produced by bundle, or whether I should put it somewhere.

And I noticed, that paths are relative to src/main/resources. Is there also option how to access files outside of that?

Community
  • 1
  • 1
juraj
  • 33
  • 4

2 Answers2

1

So the steps are pretty much like described in the README.md

  1. You start with dependency

    dependencies {
        compile 'com.bazaarvoice.dropwizard:dropwizard-configurable-assets-bundle:0.2.0-rc1'
    }
    
  2. AssetBundleConfiguration interface needs to be implemented by you standard configuration file. So in my case:

    public class BookRespositoryConfiguration extends Configuration 
                 implements AssetsBundleConfiguration {
        @Valid
        @NotNull
        @JsonProperty
        private final AssetsConfiguration assets = new AssetsConfiguration();
    
        @Override
        public AssetsConfiguration getAssetsConfiguration() {
            return assets;
        }
    }
    
  3. This configuration is referred in you Application class

    public class BooksRepositoryApplication 
                 extends Application<BookRespositoryConfiguration> {
    
        @Override
        public void initialize(Bootstrap bootstrap) {
            bootstrap.addBundle(new ConfiguredAssetsBundle("/assets/", "/books/"));
        }
    
        @Override
        public void run(BookRespositoryConfiguration configuration, 
                        Environment environment) throws Exception {
            //...
         }
     }
    
  4. And finally configuration. The configuration path is relative to the document-root, so in my case the assets are located outside the application folder.

    assets:
        overrides:
            /books: ../book-repository
    

Now after running the app you can easily navigate to http://localhost:8080/books/some-static-files.html

Jakub Marchwicki
  • 788
  • 9
  • 21
0

Look at upto-date dropwizard-configurable-assets-bundle maintained at official dropwizard-bundles.

https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle.

Olesia
  • 144
  • 4