Sunday, 22 December 2013

Day 5, display a Hello world !


Today, my first goal, is to setup my dev env to be able to run Tomcat 7 embebed in my IDE and display a simple static jsp file.

First, lets remind you my application software architecture.

/introscope-couchbase-content
 |_______ icc-business (business rules module)
 |_______ icc-couchbase-consumer (dao to couchbase)
 |_______ icc-rest-provider (ReSTful API exposure)
 |_______ icc-technical (Exception and Log module)


Add your webapp maven module :
Before setting up your App Server, you need to build a War file. this War file will be deployed in the Tomcat server. This War file will be build and package using Maven. I call my new maven module - icc-war-module.

/introscope-couchbase-content
 |_______ icc-business (business rules module)
 |_______ icc-couchbase-consumer (dao to couchbase)
 |_______ icc-rest-provider (ReSTful API exposure)
 |_______ icc-technical (Exception and Log module)
 |_______ icc-war-module (All the web stuff is here)

In this module, I need to add a web.xml file and a jsp file to be sure my deployment in tomcat 7 is ok. Find below, how my web module is constructed.

/icc-war-module
 |___ src
           |___ main
                     |___ webapp
                                 |___ WEB-INF
                                 |             |___ web.xml
                                 |___ index.jsp

The jsp file contains a simple Hello World like code. Nothing really difficult.

Tomcat 7 installation :
Now, you have a project ready to be deployed, let's configure Tomcat 7 embeded server in IntelliJ.
In a IntelliJ, you add your embeded Tomcat 7 app server using the Edit Configuration menu. Then click on the "+ button, choose Tomcat Server --> Add Local Server.

Add to the "before launch" configuration all the different actions you want to execute (make, mvn clean install and build war).

Update your war module pom :
In your pom.xml file, don't forget to add the tomcat7-maven-plugin to be able to construct your war file.
<plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
</plugin>

Source files available on Github :
If you want, you can find on my Github all the source files ready to run for this post. I have created a brachn called day5-tomcat7-embeded-minimum-configuration if you want to test it.

> git clone https://github.com/herveDarritchon/introscope-couchbase-content.git
> cd introscope-couchbase-content
> git checkout day5-tomcat7-embeded-minimum-configuration

For those who wants to create an application from this core files, I suggest you to follow the next mvn command line to create and use a maven archetype. Change directory to your root module directory and type the following command.
> mvn archetype:create-from-project
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
> cd target/generated-sources/archetype/
> mvn install
...
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...

Now you can create a project from your new archetype. Change directory to a new one and type the following command
> mvn archetype:generate -Dicc-parent-archetype
...
XXX: local -> com.orange.introscope-couchbase-content:icc-parent-archetype (icc-parent-archetype)
...
> Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 333: XXX [type the number of the archetype in the list]

After, you have to fill in the form (groupId, artifactId, version, package) and validate by typing 'Y'. You have instansiate a new project, you just have to go inside de project directory and type :
> mvn clean install tomcat7:run

Open a browser and type the URL http://localhost/[your artifactId]
You should see a 'Hello world' message : Your app is ready for dev !

No comments :

Post a Comment