Friday, August 31, 2007

Use Maven2 with Eclipse WTP

Maven verion: 2.0.7
Eclipse Version: 3.3.0
Build id: I20070625-1500

The following is how I setup a maven web project that can be hot deployed using eclipse WTP.

1. Create maven web project

mvn archetype:create
-DgroupId=[your projects group id]
-DartifactId=[your project's artifact id]
-DarchetypeArtifactId=maven-archetype-webapp

ref

2. Create dynamic web project in eclipse

Replace maven generated WEB-INF and META_INF with eclipse generated WEB-INF and META-INF

3. Create M2_REPO variable in eclipse and point it to ~/m2/repository

4. Create src/main/java and src/main/test folder

5. Point eclipse source folder to src/main/java and src/main/test folders.

6. Delete eclipse WTP default WebContent folder.

7. Switch to navigaton view and modify org.eclipse.wst.common.component file
i.e.

<?xml version="1.0" encoding="UTF-8"?>
< project-modules id="moduleCoreId" project-version="1.5.0">
< wb-module deploy-name="MyWebApp">
< wb-resource deploy-path="/" source-path="/src/main/webapp"/>
< wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
< wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
< property name="context-root" value="MyWebApp"/>
< property name="java-output-path" value="build/classes"/>
< /wb-module>
< /project-modules>

8. Modify pom.xml file and add the following plugin configuration

< build>
< finalName>MyWebApp</finalName>
< plugins>
< plugin>
< groupId>org.apache.maven.plugins</groupId>
< artifactId>maven-eclipse-plugin</artifactId>
< configuration>
< buildoutputdirectory>src/main/webapp/WEB-INF/classes
< /buildoutputdirectory>
< downloadsources>true</downloadsources>
< /configuration>
< /plugin>
< /plugins>
< /build>

9. Add dependent libraries to the pom.xml

10. run mvn eclipse:eclipse

Friday, August 17, 2007

Architectural view of Web Applications

The main concepts of MVC

  • The model handles application and business logic

  • The view handles presentation logic

  • The controller accepts and interprets keyboard and mouse input.


The motivation behind MVC was to separate the model code from its presentation. The model code does not contain any UI information, but it broadcasts notification of any state changes to dependents, which are typically views.
This scheme provides a good separation between these three layers but suffers from two weaknesses.

  • It has a simplistic view of the model and does not account for any difference between application logic (for example, flow of control and coordination of multiple Web pages) and business logic.

  • Most rich-client libraries and windowing system combine the view and controller functions in a single widget, making the logical separation into view and controller less userful.


MVC framework has evolved.

Controller: object handling application logic.
Model:business objects.

Controller
Input Controller


The input controller is a central feature. There is a single input controller for all pages in a Web application. The input controller parses input, determines the parameter-passing mechanisms, extracts any necessay information from the request, cooperates with the application controller to determine the next operatioin (typically called an action), and invokes that action in the correct context. By having a single component as an input controller, any knowledge of HTTP or naming conventions is localized at the request level. This reduces the amount of code duplication and the total size of code. Note that the input controller component is typicaly a servlet, and there may be one instance for accessing the application over HTTP via a regular Web browser and another instance for mobile applications using a Wireless Application Protocol (WAP) enabled device.


Application Controller


The application controller is typically a regular Java object. It coordinates logic related to the application flow, handles errors, maintains longer-term state, and determines which view to display. Application controllers typically need a mapping orequests to the application objects that manage the flow. Most frameworks maintain these mappings in complex XML configuration files.