How to use different repository access protocols in SVNKit?

When you have downloaded the latest SVNKit binaries and ready to start using it, a question arises: what initialization steps should be performed in order to set up the library? Direct interacting with a Subversion repository is carried out by a low-level layer, where the main class representing a repository access driver interface is an abstract SVNRepository class. There are several protocol specific realizations of this driver, one for each protocol. Each driver is created by an abstract factory class - SVNRepositoryFactory, which also has several protocol specific realizations, each one for each protocol. The following table matches a protocol against a corresponding SVNRepositoryFactory realization:


SVNRepositoryFactory realization







Instructions on initializing SVNKit

/!\ Prior to using the library you must set up an appropriate SVNRepositoryFactory realization for a particular protocol. For example, if you would like to work with a repository via the svn:// protocol, you must register the following factory:

   1        try {
   2             SVNRepositoryFactoryImpl.setup();
   3             ...
   4        } catch (SVNException e) {
   5             //handle exception
   6        }

After this step SVNRepositoryFactory knows how to create SVNRepository drivers specific for the svn:// protocol since it now contains the registered factory. And further you create a driver itself:

   1        try {
   2             ...
   3             SVNURL url = SVNURL.parseURIDecoded( "svn://host/path_to_repository_root/inner_path" );
   4             SVNRepository repository = SVNRepositoryFactory.create( url, null );
   5             ...
   6        } catch ( SVNException e ) {
   7             //handle exception
   8        }

In SVNKit all repository urls are represented by the SVNURL class. If a path string is not UTF-8 encoded yet, use the SVNURL's parseURIDecoded() method to create a new url representation (it will be encoded if necessary). Then you pass the url representation to the SVNRepositoryFactory to create a new SVNRepository driver. So, this way you can bind your driver to any repository location you would like.


The diagram above illustrates how different drivers are created for different repository paths: one for the repository root (svn://host/path_to_root), one for a directory (svn://host/path_to_root/dirA) and one for a file (svn://host/path_to_root/dirB/fileB1). Most operations which SVNRepository driver can perform against a repository, accept a repository path which may be one of two types:

Using high-level layer

When you use SVNKit for managing Working Copies you also should set up appropriate factory classes since the high-level layer uses the low-level one for working with a repository. If you miss this initialization step you may get an exception saying that SVNKit could not create an SVNRepository object for the provided url.

SVN*Client classes

All high-level operations for managing Working Copies are logically divided to SVN*Client classes: each SVN*Client class joins a separate group of operations (for example, SVNUpdateClient provides API on update operations, such as checkout, update, switch, export). There're two different ways of instantiating objects of these classes:

Getting_Started_With_SVNKit (last edited 2008-02-20 19:21:29 by nat7)