> ## Content Index
> Fetch the complete content index at: https://honstain.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# New Dropwizard 1.0.5 Java Service
- URL: https://honstain.com/new-dropwizard-1-0-5-java-service/
- Published: 2016-12-10T21:45:29.000Z
- Updated: 2026-06-21T00:33:25.000Z
- Author: Anthony Honstain
- Tags: Dropwizard, Java, mvn, #Import 2024-01-27 15:52

Dropwizard is a great tool for creating RESTful Java services. Are you interested in a walk-through of standing up a fresh Dropwizard service? Here are some resources you might find helpful, and the example I created while going through the process.

What you should get from this post?

- A basic Dropwizard service.
- Build a shaded jar with maven.
- An initial integration test.

### Introduction

This assumes you have done a quick review of:

- [http://www.dropwizard.io/1.0.5/docs/getting-started.html](http://www.dropwizard.io/1.0.5/docs/getting-started.html?ref=honstain.com)
- [https://github.com/dropwizard/dropwizard](https://github.com/dropwizard/dropwizard?ref=honstain.com)
- Definitely worth checking out the google group - [https://groups.google.com/forum/#!forum/dropwizard-user](https://groups.google.com/forum/?ref=honstain.com#!forum/dropwizard-user)

The official Dropwizard getting-started project has gotten significantly better as the project has matured.

I did all of this on:

- Ubuntu 16.04.1 LTS Xenial
- openjdk version "1.8.0\_91"
- Apache Maven 3.3.9

### Getting Started

The part that troubled me the most in getting a dropwizard service off the ground was getting maven or gradel setup so that I could get a build running. On many of the production systems I worked with, the maven choices were long set in stone. So I rarely got to experience standing one up from scratch. Your experience may differ.

I created a **VERY** bare bones example, it is basically just the result of what you get from going the official getting-started.html project.

[https://github.com/AnthonyHonstain/dropwizard-simple-skeleton](https://github.com/AnthonyHonstain/dropwizard-simple-skeleton?ref=honstain.com)  
All you need to do is:

- Pull down the repo `git clone https://github.com/AnthonyHonstain/dropwizard-simple-skeleton.git`
- Build the project `mvn package`
- Start the jar `java -jar target/hello-world-0.0.1-SNAPSHOT.jar server hello-world.yml`

Boom! You have should have a java service running locally.  
![happy](https://honstain.com/content/images/2017/01/so_happy.PNG)

###### Alternatives - Official Sample Service

The dropwizard project now provides an official example project that has some great references [https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example](https://github.com/dropwizard/dropwizard/tree/master/dropwizard-example?ref=honstain.com)

###### Alternatives - If you want to Archetype

Dropwizard provides an official mvn archetype [https://github.com/dropwizard/dropwizard/tree/master/dropwizard-archetypes](https://github.com/dropwizard/dropwizard/tree/master/dropwizard-archetypes?ref=honstain.com) but in general I would prefer to interact with a basic sample/skeleton project (I do not personally enjoy constructing or updating archetype projects - the cost of creating+maintaining doesn't usually make sense for me.

### Everyone Needs Tests

I love automated testing, hence I refuse to move forward without immediately having some reasonable scaffolding in place for unit and integration tests.

The official documentation gives you a good overview of your options: [http://www.dropwizard.io/1.0.5/docs/manual/testing.html](http://www.dropwizard.io/1.0.5/docs/manual/testing.html?ref=honstain.com)

I went ahead with a pretty simple integration test, the confusing part for me was making sure the config file was in the right place for testing (I needed to create a hellow-world.yml config under src/test/resources).

```Java
package com.example.helloworld;

import com.google.common.base.Optional;

import com.example.helloworld.core.Saying;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit.DropwizardAppRule;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;

import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Client;

import static org.junit.Assert.assertEquals;

public class IntegrationTest {

    private static final String CONFIG_PATH = ResourceHelpers.resourceFilePath("hello-world.yml");

    @ClassRule
    public static final DropwizardAppRule<HelloWorldConfiguration> RULE =
            new DropwizardAppRule<>(HelloWorldApplication.class, CONFIG_PATH);

    private Client client;

    @Before
    public void setUp() {
        client = ClientBuilder.newClient();
    }

    @After
    public void tearDown() {
        client.close();
    }

    @Test
    public void testHelloWorld() {
        final Optional<String> name = Optional.of("TestName");
        final Saying saying = client.target("http://localhost:" + RULE.getLocalPort() + "/hello-world")
                .queryParam("name", name.get())
                .request()
                .get(Saying.class);
        assertEquals("Hello, " + name.get() + "!", saying.getContent());
    }
}

```

Which should run automatically when you build `mvn package` or `mvn test`

### Results

Now you should have a basic Dropwizard service with tests that can respond to requests at [http://localhost:8080/hello-world](http://localhost:8080/hello-world?ref=honstain.com)

Cheat sheet:

```bash
# Clean up past work.
mvn clean

# Create a new shaded jar and run tests.
mvn package

# Start the dropwizard service.
java -jar target/dropwizard-sample-0.0.1-SNAPSHOT.jar server hello-world.yml

```

![build example](https://honstain.com/content/images/2017/01/dropwizard_start_local.PNG)