Creating a Maven Web-Service in IntelliJ

Here is a step-by-step procedure on making a Maven web-service using Java in the IntelliJ Environment.

Open IntelliJ and go to File > New project. In the popup that opens, select Maven on the left and check the checkbox Create from archetype and select maven-archetype-webapp.

Give your project a group-id and an artifact id. The group id could be something like com.testpackage, and the artifact id something like testproject. Leave all other settings as they are and continue to finish. This should create a new project.

In the pom.xml (or testproject.xml) file, add the dependencies for rest-easy.

Add the jetty plugin to the plugins block. We would be using the jetty server to run our web-service.
(Note: This documentation assumes that you have maven installed and added to your PATH variable, such that you can use the mvn command from the terminal.)

Add the following content to your web.xml file, which is present in src > main > webapp > WEB-INF:

Create a directory named java within main. Right click on the java directory and go to Mark Directory as and select Sources Root.

Right click on the java directory and select new package. Create two packages: and

In the package, create a new Java Class and name it EntryPoint. Copy the following content into

package; // {{ groupId}}.app
// import the rest service

import java.util.HashSet;
import java.util.Set;

public class EntryPoint extends Application {
  private Set singletons = new HashSet();
  public EntryPoint() {
      // Register our rest service
      singletons.add(new RestService());
  public Set getSingletons() {
      return singletons;

In the package, create a new Java Class named RestService. Add the following code to the file:


import java.util.*;
import java.sql.*;
import org.apache.commons.dbutils.DbUtils;

public class RestService {
  public Response isReady() {
      return Response.status(200).entity("ready").build();
You have successfully created a maven web-service!

To build and run the webservice, open the terminal within IntelliJ and use the following commands:

$ mvn clean install
(to build the project)

$ mvn jetty:run
(to run the web-service)

The port at which the web-service is running would be given in the terminal. To test the web-service, open any browser and go the the url: localhost:/testproject/isReady
You should get a response ready in your browser. The service is running!

To add methods to the service, use the annotations similar to those in the isReady() method, and add the methods in the file.


Popular posts from this blog

Hosting a Website and Creating a DNS Server

Creating a Mail Server Using Webmin