Child pages
  • Webservice getting started guide
Skip to end of metadata
Go to start of metadata

Draft description of how to setup a maven project for providing REST webservices using Jersey.

Project setup

The following project setup description assumes Eclipse is used, and that Eclipse is maven aware (i.e. can create maven based projects).

Choose to create a new project, and as type select Maven Project. Accept the first set of defaults and move forward to choosing archetype. As archetype select webapp-javaee6. On the next page in the wizzard fill in the appropriate Artifact and Group ID, and accept the project.

Next open the pom.xml file for the newly created project to edit it.

In the dependencies section insert the appropriate bitrepository dependencies and the following required for jersey:

Jersey dependencies


Besides the dependencies add the usual maven stuff related to bitrepository modules e.g.:

  • Parent pom
  • Dependencies (those which are not covered above)
  • Repositories (if needed)
  • Scm section
  • Issue Management section
  • ciManagement section
  • Distribution management section
  • Organization

If the above sounds nuts, take a look at the pom.xml for the bitrepository-webclient module, and use that as a basis.

Adding boot strapping files/code

To enable an applicationserver (say Tomcat), to expose the REST methods, a web.xml file needs to be setup. The file should be placed in src/main/webapp/WEB-INF/web.xml. web.xml file from the bitrepository-webclient can serve as an example:

Bitrepository-webservice web.xml
<?xml version="1.0" encoding="UTF-8"?>
  <display-name>Bitrepository webservice</display-name>





The content of the <param-value> element inside <init-param> should contain the name of the package containing the JAX-RS (JRS-311) annotated classes and methods.

The <listener-class> element is handy to implementing a class to handle startup and shutdown of the webapp. See bitrepository-webclient for reference.

To expose methods as REST calls JAX-RS (JRS-311) annotations should be used. Documentation hereof can be found here.

For integration with the bitrepository-webclient it is desired that a html page is made which should serve as the access method of the service. This way it can be referenced by the webclient and put on it as a tab.

Logback logging

If nothing is done, logback logs will end up in tomcats 'catalina' log. To change this the class LogbackConfigLoader below can be used.

By running its constructor with the path and filename to a logback configuration file (i.e. logback.xml), logback can be configured. This should be done from the 'ShutdownListener' referred to in the web.xml file above.

public class LogbackConfigLoader {
	private Logger log = LoggerFactory.getLogger(LogbackConfigLoader.class);

	public LogbackConfigLoader(String configFileLocation) throws IOException, JoranException{
		LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
		File configFile = new File(configFileLocation);
			throw new IOException("Logback External Config File Parameter does not reference a file that exists");

			throw new IOException("Logback External Config File Parameter exists, but does not reference a file");

			throw new IOException("Logback External Config File exists and is a file, but cannot be read.");

		JoranConfigurator configurator = new JoranConfigurator();
		configurator.doConfigure(configFileLocation);"Configured Logback with config file from: " + configFileLocation);

  • No labels