Skip to content
Switch branches/tags
Go to file

Java URL builder

Build Status Coverage Status Maven Central

Create and modify URLs and URL parameters easily, with a builder class.

Builder instances are immutable, thread-safe and reusable. Every change creates a new instance.

    .addParameter("q", "charlie brown")
    .toString() == ""

UrlBuilder.fromString("http://foo/h%F6pl%E4", "ISO-8859-1")
    .toString() == "http://foo/h%C3%B6pl%C3%A4"

final UrlBuilder ub1 = UrlBuilder.empty()
    .addParameter("foo", "bar");

final uri1 = ub1.toUri();

try {
    final uri2 = ub1.toUriWithException();
} catch ( ex) {
    // handle the exception

final url1 = ub1.toUrl();

try {
    final url2 = ub1.toUrlWithException();
} catch ( ex) {
    // handle the exception


  • More unit tests for corner cases. Please send in pull requests, your help is needed.

Use with Maven: