Git Product home page Git Product logo

dropwizard-webjars-bundle's Introduction

dropwizard-webjars-bundle

A Dropwizard bundle that makes it a lot easier to work with WebJars.

Regular java code doesn't need to know or care about what version of a dependency it is using. It simply imports the class by name and goes on about its business. Why shouldn't your front-end development work the same way? This bundle automatically injects version information for you.

Build Status

Getting Started

Just add this maven dependency to get started:

<dependency>
    <groupId>io.dropwizard-bundles</groupId>
    <artifactId>dropwizard-webjars-bundle</artifactId>
    <version>1.0.5</version>
</dependency>

Add the resource to your environment:

public class SampleApplication extends Application<Configuration> {
    public static void main(String[] args) throws Exception {
        new SampleApplication().run(args);
    }

    @Override
    public void initialize(Bootstrap<Configuration> bootstrap) {
        bootstrap.addBundle(new WebJarBundle());
    }

    @Override
    public void run(Configuration cfg, Environment env) throws Exception {
        // ...
    }
}

Now reference your WebJar omitting version information:

<script src="/webjars/bootstrap/js/bootstrap.min.js"></script>

Customizing cache settings

By default the WebJar bundle has conservative, but reasonable, cache settings to ensure that WebJar resources are returned quickly to your clients. If for some reason the built-in settings aren't suitable for your application they can be overidden by invoking the WebJarBundle constructor with a com.google.common.cache.CacheBuilder instance that is configured with your desired caching settings.

The cache that is built by the WebJarBundle will include a com.google.common.cache.Weigher as part of it that indicates how many bytes each resource is taking up in the cache. If desired you can include a maximum weight in your CacheBuilder to limit the amount of memory used by the cache.

Customizing WebJar groups

Custom WebJars artifacts often appear in a maven group other than org.webjars. In order to support these custom WebJars, just invoke the WebJarBundle constructor with a list of the group names you would like to be considered by the bundle.

Don't forget to also include org.webjars in your list if you want standard WebJars to be found as well.

dropwizard-webjars-bundle's People

Contributors

bbeck avatar bvbuild avatar nbauernfeind avatar tianx2 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.