Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Monday, March 10, 2014

Getting started with RESTful webservice using Jersey

Jersey helps developing RESTful webservices seamlessly and makes your life easy. This article gives you a quick start on how to create your first RESTful web service using Jersey & Maven.  I assume you have a decent understanding of maven and J2EE.

Make sure you have
  1. Eclipse Kepler
  2. M2Eclipse plugin
  3. Java 1.7
  4. Tomcat 7
Step 1 - Maven Project
Create a new maven project from your eclipse.  Select maven-archetype-webapp archetype,  provide group id, artifact id, package in the following dialog. (See screenshot below)


Note: By default installed facets will not be Java 1.7, Dynamic web module 2.4.  You can edit this in org.eclipse.wst.common.project.facet.core.xml under .settings folder.  Also make sure to change the JRE from 1.5 to 1.7 in your project build path.

Step 2 - Maven Dependencies
Add the following jersey server and jersey servlet dependencies to your pom.xml
Step 3 - Deployment Descriptor
Add the Jersey servlet container to your web.xml.
Step 4 - REST Resource
Create your package and SampleRestResource class.  Add the path "/sample" at the class level, and add 2 GET resources. One with path "/hello" and the other with "/hello/{message}".  
Step 5 - Run your application
Right click on your project --> Run As --> Run on Server --> Select tomcat.  Now your first resource can be accessed from http://localhost:8080/jersey-rest-helloworld/jersey/sample/hello and the other resource from http://localhost:8080/jersey-rest-helloworld/jersey/sample/hello/your%20message

You can download the complete source here.

Friday, November 15, 2013

Spring MVC 3 - hello world example - Quick start

This tutorial helps you to quickly create and run a spring-mvc hello world application.  Spring version used for this example is 3.2.3-RELEASE.

Prerequisites
  1. JDK 1.6+
  2. Eclipse Juno+
  3. Spring IDE 3.4+ for eclipse
  4. Maven 3
  5. Maven Integration plugin for eclipse
  6. Tomcat 7+
Initial Steps
Right click and create New --> Spring project.  In the next dialog, fill in the project name as "spring-mvc-spring-sample" and select "Spring MVC Project".  Please specify package name "com.ananth.spring" and click Finish.


Run your application
Right click on your eclipse project --> Run As --> Run on server --> Finish.
From your browser navigate to http://localhost:8080/spring/ you will see this screen.

The source can be download from github. Next chapter Spring MVC with Spring security & Hibernate.

Monday, June 17, 2013

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

I got this exception while I was trying to execute an open source application that I found from the web. I was trying to run the application from my eclipse managed tomcat 7 server. I noticed that my project's maven dependencies were not having the right jars.
This problem can be fixed by adding maven dependencies in the project's web deployment assembly.
  1. Open the project's properties (e.g., right-click on the project's name in the project explorer and select "Properties")
  2. Select "Deployment Assembly"
  3. Click the "Add..." button on the right margin
  4. Select "Java Build Path Entries" from the menu of Directive Type and click "Next"
  5. Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish".
You should see "Maven Dependencies" added to the Web Deployment Assembly definition after the following the above steps.

Tuesday, May 7, 2013

What is maven batch mode

Maven batch mode

Batch mode is to run Maven in a non-interactive, continuous integration environment. When running in non-interactive mode, Maven will never stop to accept input from the user. Instead, it will use default values when it requires input.

How to run maven in batch mode

Pass one of the params below to mvn command from your terminal,

--batch-mode, B