I have a Dropwizard based Jersey REST service running on the default ports 8080(service) and 8081(admin), I need to change the default ports to something that is less commonly used, I am not able to find any information to do so , can someone please point me to do so ?
11 Answers
You can update the ports in your yaml configuration file:
http:
port: 9000
adminPort: 9001
See http://www.dropwizard.io/0.9.2/docs/manual/configuration.html#http for more information.
EDIT
If you've migrated to Dropwizard 0.7.x, 0.8.x, 0.9.x you can use the following:
server:
applicationConnectors:
- type: http
port: 9000
adminConnectors:
- type: http
port: 9001
-
Thanks , but just setting these ports in the .yml file in my project is not changing the default ports , it still runs on 8080. Is there a default yaml file,different than the one that I have for my service that I need to use in order to put in these new values? – user1965449 Nov 19 '13 at 04:43
-
Strange - it works for me. How are you specifying your configuration file? Should be on the Java command line when you're launching your service... – condit Nov 19 '13 at 16:45
-
I have a .yml file directly under the project folder in eclipse and run the service using a fat jar "java -jar myservice.jar server",I dont specify it using the command line , are there two config files here ? one for the service and one for the configuration ? I am following the tutorial for getting started. Is this configuration file the same as the .yml file that the tutorial mentions for the Hello World example ? – user1965449 Nov 19 '13 at 19:04
-
4Add your configuration to the command line after `server`. See http://dropwizard.codahale.com/getting-started/#running-your-service for more information. It should have the desired effect. – condit Nov 19 '13 at 20:46
-
Perfect! Thanks a lot , I really appreciate that , I was under the impression that the config file would be automatically picked up . Now that I specify it in the command line it works like a charm! – user1965449 Nov 20 '13 at 05:09
-
One minor comment - I couldn't edit the answer because it was just 1 character - but needs to be http: not http - because you get parsing error without : – mikemil Feb 05 '14 at 21:17
-
java -jar
server <.yml path> – Somnath Musib Jun 22 '19 at 09:06
From the command line, you can set them this way, in Dropwizard 0.6:
java -Ddw.http.port=9090 -Ddw.http.adminPort=9091 -jar yourapp.jar server yourconfig.yml
If you use Dropwizard 0.7, the system properties are set this way:
java -Ddw.server.applicationConnectors[0].port=9090 -Ddw.server.adminConnectors[0].port=9091 -jar yourapp.jar server yourconfig.yml
I seems that, if you configure ports through system properties, you also need to set them in the yml (the system property takes precedence, anyway). At least that's happening to me in Dropwizard 0.7. Example of the YAML port configuration:
server:
applicationConnectors:
- type: http
port: 8090
adminConnectors:
- type: http
port: 8091
If you don't put those ports in the YAML, Dropwizard complains:
Exception in thread "main" java.lang.IllegalArgumentException: Unable to override server.applicationConnectors[0].port; node with index not found.

- 10,919
- 16
- 85
- 100
This is what I've done for my test applications (0.7.x, 0.8.x, 0.9.x):
public class TestConfiguration extends Configuration {
public TestConfiguration() {
super();
// The following is to make sure it runs with a random port. parallel tests clash otherwise
((HttpConnectorFactory) ((DefaultServerFactory) getServerFactory()).getApplicationConnectors().get(0)).setPort(0);
// this is for admin port
((HttpConnectorFactory) ((DefaultServerFactory) getServerFactory()).getAdminConnectors().get(0)).setPort(0); } }
0 gives a random port that is available.
I know it's not pretty but couldn't find a better way to do it programmatically. I needed to make sure ports don't clash between different integration tests, because they run in parallel. Creating a yml file randomly for each test would have been uglier I believe.
Oh and this is how you get the running port later on:
@Override
public void run(TestConfiguration configuration, Environment environment) throws Exception {
this.environment = environment;
// do other stuff if you need to
}
public int getPort() {
return ((AbstractNetworkConnector) environment.getApplicationContext().getServer().getConnectors()[0]).getLocalPort();
}

- 2,816
- 20
- 37
I never work with dropwizard before, only creating simple services using jersey. I decided to see the user's manual, and immediately found a description of the settings.
Dropwizard configuration manual
You can override configuration settings by passing special Java system properties when starting your service. Overrides must start with prefix dw., followed by the path to the configuration value being overridden. For example, to override the HTTP port to use, you could start your service like this:
java -Ddw.http.port=9090 server my-config.json
Is it suitable for you?

- 21,755
- 5
- 88
- 103

- 2,713
- 8
- 26
- 39
If you want it to be changed at run-time use
-Ddw.server.applicationConnectors[0].port=9090 -Ddw.server.adminConnectors[0].port=9091
I have used it with version 1.0.5

- 113
- 1
- 10
For Dropwizard 0.8.0 --
Your YAML file can be -
server: type: simple connector: type: http port: 80
If you want to change the ports from command-line,
java -Ddw.server.connector.port=9090 -jar yourapp.jar server yourconfig.yml
The command will work only if you have the entry in the YAML file. DW needs a default value which it can override .

- 389
- 4
- 6
For Dropwizard 0.6.2 you can change the port programmatically as below in your service class.
import com.yammer.dropwizard.config.Configuration;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.config.HttpConfiguration;
import com.yammer.dropwizard.Service;
public class BlogService extends Service<Configuration> {
public static void main(String[] args) throws Exception {
new BlogService().run(new String[] {"server"});
}
@Override
public void initialize(Bootstrap<Configuration> bootsrap) {
bootsrap.setName("blog");
}
public void run(Configuration configuration, Environment environment) throws Exception {
HttpConfiguration config = new HttpConfiguration();
config.setPort(8085);
config.setAdminPort(8086);
configuration.setHttpConfiguration(config);
}
}

- 783
- 4
- 10
- 23
I needed to set the ports but I couldn't set them from the command line. I ended up with this solution:
public static void main(String[] args) throws Exception {
String applicationPort = "9090";
String adminPort = "9091";
System.setProperty("dw.server.applicationConnectors[0].port", applicationPort);
System.setProperty("dw.server.adminConnectors[0].port", adminPort);
new Main().run(args);
}
This is done using Dropwizard 1.3.0-rc7

- 4,098
- 3
- 18
- 25
In the newer version of dropwizard (e.g. 2.0.25): create a property file config.yml with the following content into your resources directory:
server:
applicationConnectors:
- type: http
port: 5020
adminConnectors:
- type: http
port: 5022
If using Intellij IDE (ver 2021), remember to add the following to Run Configuration Program argument:
server src/main/resources/config.yml

- 930
- 8
- 16
this is where you can all configuration require to solve your problem https://www.dropwizard.io/en/latest/manual/configuration.html

- 11
- 2
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32385412) – AddeusExMachina Aug 05 '22 at 07:06
In your .yml file make these changes
server:
registerDefaultExceptionMappers: false
applicationConnectors:
- type: http
port: 5020
adminConnectors:
- type: http
port: 5022

- 5
- 1