The current library has undergone a major overhaul and is now released as a beta version.
We recommend upgrading from prior versions of rollbar-java
, but that process may require some
work on your end for the more complex use cases of the old library.
The code is documented with javadoc and therefore should be usable from viewing
the documentation in the source. There are examples in the examples
directory showing different
use cases for consuming these libraries.
There are currently four libraries in this repository:
rollbar-api
rollbar-java
rollbar-web
rollbar-android
rollbar-api
is a set of data objects representing structures that make up the payload
the backend API understands.
rollbar-java
has the core functionality for taking input from your code and transmitting
it to our API. rollbar-java
depends on rollbar-api
and provides many points of
customizing its behavior.
rollbar-web
is a higher level abstraction built on rollbar-java
which intended to be
integrated into web servers based on the Servlet API.
rollbar-android
is a library for use in an Android environment built on rollbar-java
.
The example directory contains examples using rollbar-java
directly as well as using
rollbar-web
and rollbar-android
.
To report problems or ask a question about the alpha release, please create an issue and apply the label 1.0.0-beta
so our team can follow up with you.
compile('com.rollbar:rollbar-java:1.0.0-beta-2')
This package used to be divided into five modules
rollbar-utilities
rollbar-testing
rollbar-sender
rollbar-payload
rollbar
As of 1.0.0 we have changed the project structure to these modules
rollbar-api
rollbar-java
rollbar-web
rollbar-android
rollbar-api
contains roughly the same objects as rollbar-payload
previously did. The main
difference being that the objects are now constructed via builders rather than a new allocation in
every setter. Therefore, any usage of rollbar-payload
objects is still possible, but the style is
slightly changed. For example, one of the examples for specifying the server information from the
old documentation
https://github.com/rollbar/rollbar-java/tree/496eb59edea7203a246f207986e332ee28d1916c/rollbar
stated:
Server s = new Server()
.host("www.rollbar.com")
.branch("master")
.codeVersion("b01ff9e")
.put("TAttUQoLtUaE", 42);
The equivalent is now:
Server s = new Server.Builder()
.host("www.rollbar.com")
.branch("master")
.codeVersion("b01ff9e")
.build();
The Extensible base class from rollbar-utilities
is no longer used in favor of sticking more
closely to the spec.
The other use cases from those old docs was calling send
directly on a Payload
object:
// Throwable t
Payload p = Payload.fromError(SERVER_POST_ACCESS_TOKEN, ENVIRONMENT, t, null);
p.send();
This is no longer directly supported. The equivalent is to use Rollbar
directly, either by
constructing a new instance (new Rollbar(config)
) or by using the library managed singleton
(Rollbar.init(config)
):
// Throwable t
Config config = withAccessToken(SERVER_POST_ACCESS_TOKEN)
.environment("development")
.build();
Rollbar rollbar = Rollbar.init(config);
rollbar.error(t);
There is a shim that has the same basic API as the old library located in the rollbar-java
package at com.rollbar.Rollbar
. This class is marked as deprecated as it is only intended to
make upgrading slightly more convenient. This old example code should still work thanks to this shim class:
import com.rollbar.Rollbar;
public class MainClass {
public static final Rollbar rollbar = new Rollbar("ACCESS_TOKEN", "production");
public int main(String[] args) {
rollbar.handleUncaughtErrors();
OtherClass.runProgram();
return 0;
}
}
However, we strongly advise upgrading to at least this equivalent using the new library:
import com.rollbar.notifier.Rollbar;
public class MainClass {
public static final Rollbar rollbar = new Rollbar(
withAccessToken("ACCESS_TOKEN")
.environment("production")
.handleUncaughtErrors(true)
.build());
public int main(String[] args) {
OtherClass.runProgram();
return 0;
}
}
You can, of course, build it yourself and depend on the .jar manually, however, the modules are up on maven central and can be installed in most tool chains.
All these can be installed as Maven projects. Simply add the dependency to your pom file:
<dependencies>
<dependency>
<groupId>com.rollbar</groupId>
<artifactId>rollbar-java</artifactId>
<version>1.0.0-beta-2</version>
</dependency>
</dependencies>
compile('com.rollbar:rollbar-java:1.0.0-beta-2')
For actual usage, the easiest way to get started is by looking at the examples:
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
). - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request