Create a WebLab portlet

From WebLab Wiki
Jump to navigationJump to search

Goal of the tutorial

In this chapter we will describe the development of a new portlet easily integrable to a WebLab application. The development of portlets is possible in several frameworks, in this tutorial we chose to use Spring Web MVC framework [1]. The only requierement for portlet deployment in an existing WebLab application is to respect the Java JSR-286 specification [2]. Finally we will use maven[3] as project configuration management and building automation tool. The objective of the new portlet will be to display the title of a a WebLab document.

Next sections will detail :

  1. Creation of a Java application scheme using Maven and WebLab Archetype Plugin
  2. Implementation of the portlet class
  3. Packaging and test of portlet

Maven configuration

First of all, if it's not done, you have to install Maven (see maven documentation[4]). Then, you have to modifying the file <maven directory>/conf/settings.xml. If you already have a profile in your settings, then you just have to add this in the repositories markup :

[...]
<repositories>
[...]
    <repository>
        <id>ow2</id>
        <url>http://maven.ow2.org/maven2</url>
        <name>ow2</name>
    </repository>
    <repository>
	<id>ow2-snapshot</id>
	<url>http://maven.ow2.org/maven2-snapshot/</url>
	<name>ow2-snapshot</name>
    </repository>
    <repository>
       <id>weblab</id>
       <url>http://maven.weblab-project.org/</url>
       <name>weblab</name>
    </repository>
    <repository>
       <id>weblab-snapshot</id>
       <url>http://maven-snapshot.weblab-project.org/</url>
	<name>weblab-snapshot</name>
     </repository> 
</repositories>
[...]

If not, you have to create a new profile in the profiles mark-up, and activate the profile in the settings mark-up, such as below :

[...]
<profiles>
   <profile>
      <id>AnyIDYouWant</id> <!-- must be the same as below -->
      <activation>
         <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
         <repository>
            <id>ow2</id>
            <url>http://maven.ow2.org/maven2</url>
            <name>ow2</name>
         </repository>
         <repository>
	    <id>ow2-snapshot</id>
	    <url>http://maven.ow2.org/maven2-snapshot/</url>
	    <name>ow2-snapshot</name>
         </repository>
         <repository>
            <id>weblab</id>
            <url>http://maven.weblab-project.org/</url>
            <name>weblab</name>
         </repository>
         <repository>
	    <id>weblab-snapshot</id>
            <url>http://maven-snapshot.weblab-project.org/</url>
	    <name>weblab-snapshot</name>
         </repository> 
      </repositories>
      <pluginRepositories>
         <pluginRepository>
            <id>ow2</id>
            <url>http://maven.ow2.org/maven2</url>
            <name>ow2</name>
         </pluginRepository>
         <pluginRepository>
            <id>ow2-snapshot</id>
	    <url>http://maven.ow2.org/maven2-snapshot/</url>
	    <name>ow2-snapshot</name>
	 </pluginRepository>
         <pluginRepository>
            <id>weblab</id>
            <url>http://maven.weblab-project.org/</url>
            <name>weblab</name>
         </pluginRepository>
         <pluginRepository>
	    <id>weblab-snapshot</id>
            <url>http://maven-snapshot.weblab-project.org/</url>
	    <name>weblab-snapshot</name>
         </pluginRepository> 
      </pluginRepositories>
   </profile>
</profiles>
<activeProfiles>
    <activeProfile>AnyIDYouWant</activeProfile> <!-- must be the same as above -->
</activeProfiles>

To invoke the plugin by its prefix weblab you have to add group identifier (i.e.: mvn weblab:generate ...):

<settings ...>
[...]
    <pluginGroups>
    [...]
        <pluginGroup>org.ow2.weblab.tools.maven</pluginGroup>
    </pluginGroups>
</settings>

With this configuration, Maven can retrieve libraries needed to the next steps of this tutorial.