What is REST?
A RESTful API is an application program interface (API) that uses HTTP requests to GET, PUT, POST and DELETE data.
What is Maven?
Apache Maven. Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software: first, it describes how software is built, and second, it describes its dependencies.
Installing Maven by setting up the path in Environment Variables in Windows:
- Go to the link
download the apache-maven from the above website.
2. Unzip it.
This is the location where you can unzip the folder.
3. Right click on computer —> properties—>advanced system settings—>environment variables—>
New–> Make sure that, set the Java path.
variable name: Path
variable path : C:\Program Files\Java\jdk1.8.0_121
Set Maven path:
Click on New—->
variable name: M2_HOME
variable path : C:\Program Files\Apache Software Foundation\apache-maven-3.5.0
Click on New—>
variable name: M2
variable path = %M2_HOME%/bin
Again, click on New–>
Edit the path in System variables:
Add %M2_HOME%/bin after java path .
variable name: path
variable value: C:\Program Files\Java\jdk1.8.0_121\bin;%M2_HOME%/bin;
Open the command prompt type mvn –version:
you will see the maven details.
Maven is successfully installed into the system now, create Jersey project.
Creating a REST(Jersey) + java web application + Maven to project:
- open the command prompt. Type mvn archetype: generate for creating Maven Project.
3. Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
14 (select the archetype as jersey-quickstart-webapp)
4. Enter the version:
Choose a number: 93: 1.19.3
Click enter, again enter.
5. Add groupId, artifactId, version, package details click on enter.
Define value for property ‘groupId’: com.wavelabs.app
Define value for property ‘artifactId’: myApplication
Define value for property ‘version’ 1.0-SNAPSHOT: : 1.19.1
Define value for property ‘package’ com.wavelabs.app: : com.wavelabs.app.myApplication
Put ‘Y’ and then Enter.
The project will be created in the above location.
Version compatibility issue:
Sometimes we got the exception while creating Rest web application with Maven in Eclipse Neon. It cannot be resolved in some cases.
The exception like com.sun.jersey.api.container.ServletContainer:(It’s for 1.x version)
com.glassfish.jersey.api.container.ServletContainer:(It’s for 2.x version)
The Server cannot recognize the ServletContainer which is in web.xml.
We will install the Maven manually by setting the path in an environment variables and create the Rest Maven project in command prompt and then import that project into Eclipse Neon.
Create a dynamic web application and convert into Maven project.