Draft description of how to setup a maven project for providing REST webservices using Jersey.
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:
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
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:
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.
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.