dropwizard-file-assets

Dropwizard FileAssetsBundle - just plain files for pity's sake!

License

License

Categories

Categories

DropWizard Container Microservices
GroupId

GroupId

com.github.dirkraft.dropwizard-file-assets
ArtifactId

ArtifactId

dropwizard-file-assets
Last Version

Last Version

0.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

dropwizard-file-assets
Dropwizard FileAssetsBundle - just plain files for pity's sake!
Project URL

Project URL

https://github.com/dirkraft/dropwizard-file-assets
Project Organization

Project Organization

dirkraft
Source Code Management

Source Code Management

https://github.com/dirkraft/dropwizard-file-assets.git

Download dropwizard-file-assets

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.dirkraft.dropwizard-file-assets/dropwizard-file-assets/ -->
<dependency>
    <groupId>com.github.dirkraft.dropwizard-file-assets</groupId>
    <artifactId>dropwizard-file-assets</artifactId>
    <version>0.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.dirkraft.dropwizard-file-assets/dropwizard-file-assets/
implementation 'com.github.dirkraft.dropwizard-file-assets:dropwizard-file-assets:0.0.2'
// https://jarcasting.com/artifacts/com.github.dirkraft.dropwizard-file-assets/dropwizard-file-assets/
implementation ("com.github.dirkraft.dropwizard-file-assets:dropwizard-file-assets:0.0.2")
'com.github.dirkraft.dropwizard-file-assets:dropwizard-file-assets:jar:0.0.2'
<dependency org="com.github.dirkraft.dropwizard-file-assets" name="dropwizard-file-assets" rev="0.0.2">
  <artifact name="dropwizard-file-assets" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.dirkraft.dropwizard-file-assets', module='dropwizard-file-assets', version='0.0.2')
)
libraryDependencies += "com.github.dirkraft.dropwizard-file-assets" % "dropwizard-file-assets" % "0.0.2"
[com.github.dirkraft.dropwizard-file-assets/dropwizard-file-assets "0.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
io.dropwizard : dropwizard-core jar 1.0.0

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.0.42-beta
io.dropwizard : dropwizard-assets jar 1.0.0

Project Modules

There are no modules declared in this project.

dropwizard-file-assets

I just want to serve plain files in my Dropwizard app. That's all this does; let you serve files from your file system. It has about 0 extra features.

Build Status

Dependency

Add the dependency from Maven central.

Maven

Unverified (I use gradle these days)

<dependency>
	<groupId>com.github.dirkraft.dropwizard</groupId>
	<artifactId>dropwizard-file-assets</artifactId>
	<version>0.0.2</version>
</dependency>

Gradle

apply plugin: 'maven'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.github.dirkraft.dropwizard:dropwizard-file-assets:0.0.2'
}

Integration

This thing was mostly spurred on by development (I use IntelliJ for everything). I want to be able to refresh my browser rather than have to constantly restart dropwizard. I usually end up with two main methods: one for production and one for development. The right thing to do in production is serve static assets through nginx. The lazy thing to do is anything else, such as serving them directly from your java application.

Serving out of the classpath the traditional way with standard dropwizard-assets. Perhaps you have bundled your static assets in your jar.

Standard Dropwizard Assets Bundle

@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
    bootstrap.addBundle(new AssetsBundle("/web", "/", "index.html"));
}

See a slightly more complete example in StandardAssetsBundleApp.java

Serving directly from the filesystem thanks to this small module, for instant browser refreshability.

Dropwizard File Assets Bundle

@Override
public void initialize(Bootstrap<Configuration> bootstrap) {
    // This is a relative path, relative to the working directory. If you run this main method in IntelliJ,
    // by default the working directory is the project root directory.
    bootstrap.addBundle(new FileAssetsBundle("src/test/resources/web", "/", "index.html"));
}

See a slightly more complete example in FileAssetsBundleApp.java

If you wanted, you could map it into your custom Configuration, but I don't usually care for that stuff until much later, if ever. If you do want that, you should check out dropwizard-configurable-assets-bundle. I just found it unwieldy to get started, but once you're going you might think about switching over to that for more of its features.

Troubleshooting

On startup if you have not restricted your logging too much, you might see a message from the FileAssetsBundle explaining what it's doing.

INFO  [2015-01-20 03:27:32,380] com.github.dirkraft.dropwizard.fileassets.FileAssetsBundle: Registering FileAssetBundle with servlet name assets for request path /* from file system /Users/dirkraft/src/dropwizard-file-assets/src/test/resources/web

You can also enable debug level logging on com.github.dirkraft.dropwizard.fileassets.FileAssetServlet, which will then log the resolved absolute path to every resource request received, right before it attempts to read the file data.

License

dropwizard-file-assets is released under the Apache 2.0 license. It is a slight modification on the original dropwizard-assets module and so maintains dropwizard's licensing scheme.

Versions

Version
0.0.2