In looking at the documentation, it appears that DropWizard is only able to serve static content living in src/main/resources. I'd like to keep my static files in a separate directory outside the jar file. Is that possible? Or do most people use nginx/Apache for their static content?
相关问题
- Dropwizard/Jersey is giving “Unable to process JSO
- @Context injection not working in Jersey Container
- dropwizard: read configuration from a non-file sou
- Add jetty servlet into dropwizard
- Registering Dropwizard configuration with Jersey 2
相关文章
- How to deploy an angularjs application frontend wi
- Getting resource annotations in Jersey 1.18.1 requ
- Using Dropwizard & JDBI to query database with mul
- django-pipeline and s3boto storage don't seem
- JAX-RS in Dropwizard: Handling async call with imm
- Dropwizard and Guice: injecting Environment
- how to create a VirtualHost to serve only static c
- How to make @JsonSnakeCase the default for configu
There is a upto-date
dropwizard-configurable-assets-bundle
maintained at official dropwizard-bundles. You can find it at github https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle. Current version supports dropwizard 0.9.2This can be used to serve static files from arbitrary file system path.
The vast majority of websites that serve static content do so through a dedicated webserver, or, at larger scale, a CDN.
Occasionally, you might want to deploy an application as a self-contained unit complete with all assets which is where Dropwizard comes in.
It is possible to get Dropwizard to serve up assets from outside the classpath, but the easiest way to do this is to write your own asset endpoint that reads from an externally configured file path.
Working off of Marcello Nuccio's answer, it still took me the better part of my day to get it right, so here is what I did in a bit more detail.
Let's say I have this directory structure:
Then this is what you have to do to make it work:
1) In your dropwizard Application class, add a new AssetsBundle. If you want your assets to be served from a different URL, change the second parameter.
2) Add the document root to your classpath by configuring the maven-jar-plugin like this. (Getting the "./staticdocs/" in the correct form took me a while. Classpaths are unforgiving.)
3) This step is entirely optional. If you want to serve your Jersey REST Resources from a different root path (e.g. "app"), add the following to your configuration YML:
Now you can access your static content like this, for example:
yes, it can, using this plugin - https://github.com/bazaarvoice/dropwizard-configurable-assets-bundle
To complement craddack's answer: Correct, you can use the regular AssetsBundle as long as you add the assets to your classpath. If you use gradle and oneJar, you can add a directory to the classpath in the oneJar task:
see https://github.com/rholder/gradle-one-jar
The user manual says:
i.e. the files are loaded as resources from the classpath. Then you only need to properly set the classpath for the service.
With the default configuration, this means that you need to call the document root
assets
, and put the parent folder of the document root in the classpath. Then, for example,assets/foo.html
will be available at