Java: Basic Dropwizard Project

This entry is part 1 of 5 in the series Dropwizard
(Last Updated On: )

This tutorial will guide you through how to create a bare bones Dropwizard app. Ensure you have Eclipse installed or whatever IDE you are deciding to use. You can use their documentation as a guide. This is the first tutorial in the dropwizard series.

Setup Eclipse Archetype:

Select new Maven Project then in the select Archetype if dropwizard isn’t there you can add it by using the below settings.

Filter for Dropwizard Archetype:

Set Project Settings:

POM:

Ensure the pom has the correct “dropwizard.version” and that the dependency “dropwizard-core” is there.

Our Configuration:

Now that the project is created let’s have a look at what our configuration looks like. Pretty basic but that’s all we need right now.

  1. package ca.gaudreault.mydropwizardapp;
  2.  
  3. import io.dropwizard.Configuration;
  4. import com.fasterxml.jackson.annotation.JsonProperty;
  5. import org.hibernate.validator.constraints.*;
  6. import javax.validation.constraints.*;
  7.  
  8. public class MyDropwizardAppConfiguration extends Configuration {
  9. }

Our Application:

This is what our application class looks like. It’s empty nothing yet.

  1. package ca.gaudreault.mydropwizardapp;
  2.  
  3. import io.dropwizard.Application;
  4. import io.dropwizard.setup.Bootstrap;
  5. import io.dropwizard.setup.Environment;
  6.  
  7. public class MyDropwizardAppApplication extends Application {
  8.  
  9. public static void main(final String[] args) throws Exception {
  10. new MyDropwizardAppApplication().run(args);
  11. }
  12.  
  13. @Override
  14. public String getName() {
  15. return "MyDropwizardApp";
  16. }
  17.  
  18. @Override
  19. public void initialize(final Bootstrap bootstrap) {
  20.  
  21. }
  22.  
  23. @Override
  24. public void run(final MyDropwizardAppConfiguration configuration,
  25. final Environment environment) {
  26.  
  27. }
  28. }

Config.yml:

This is what our config.yml file looks like at the start.

  1. logging:
  2. level: INFO
  3. loggers:
  4. ca.gaudreault: DEBUG

Setup Debug Configuration:

Setup your debug configuration like the below setup.

Running:

Once you run it you will be running two sites.

  1. http://localhost:8080
    1. Your main site
  2. http://localhost:8081
    1. Your operational site (health, etc)
Series NavigationDropwizard: Guice Bundle >>

2 thoughts on “Java: Basic Dropwizard Project”

Comments are closed.