Web (Servlet)

How to configure rollbar-java to work with your web app


  1. Open your app.gradle of your project, and add the following dependencies.
  1. Log into your Rollbar account dashboard. Go to Settings β†’ Project Access Tokens and then copy the post_server_item access token.

  2. In your code, create a ConfigProvider implementation that will provide a Rollbar Config:

import com.rollbar.notifier.config.Config;
import com.rollbar.notifier.config.ConfigBuilder;
import com.rollbar.notifier.config.ConfigProvider;
import com.rollbar.web.example.server.ServerProvider;

public class MyConfigProvider implements ConfigProvider {

  public Config provide(ConfigBuilder builder) {
    return ConfigBuilder.withAccessToken("<post_server_access_token>")
        .server(new ServerProvider())
  1. Setup a listener and filter in your web.xml file:
 <!-- Rollbar listener and filter -->

        <filter-name>Rollbar Filter</filter-name>
        <filter-name>Rollbar Filter</filter-name>

At this point, all uncaught errors throw by servlets will be logged to Rollbar. If you'd like to send caught items from inside your code, proceed to step 5.

  1. Create an instance and send an error and a message.
// Create a config builder
ConfigBuilder configBuilder = ConfigBuilder.withAccessToken("<post_server_access_token>");

// Create an instance of the ConfigProvider created in step 3, for example
ConfigProvider configProvider = new MyConfigProvider();

// Create the notifier instance
Rollbar rollbar = new Rollbar(configProvider.provide(configBuilder));

// Send an error and a message
rollbar.info("This is an info message");

These two items should appear in your project's dashboard within a few seconds.

For further examples and information on using rollbar-web, check out the example app here.


For more information on rollbar-java, please see the docs here.