Tuesday, October 16, 2012

Creating a Vaadin Portlet for Liferay

Creating a basic Vaadin Portlet for Liferay is pretty simple...

Install the latest Liferay IDE using the Eclipse built in Help->Install New Software mechanism...
You will have to have download the liferay sdk, and the latest version of Liferay/Tomcat bundle and install them locally.

Once complete you can create a new portlet using the New->Liferay->Portlet and selecting Vaadin as the presentation library. This will create a working 'Hello World' application with one minor change... (There is currently a bug... you will have to modify the portlet.xml and change the init-param section as follows: application

Once this change has been made, set up your new Liferay installation under the 'Servers' tab in Eclipse, start it, and deploy the portlet to the server by right clicking the server, and selecting the 'Add and Remove' option. Browse to your local installation using http://localhost:8080 in a web browser, log in as the adminstrator (test@liferay.com/test by default), add a new page and add the newly created portlet to the page ... Add->More->Samples (it will show up under the 'Samples' section. This will display your portlet with a label saying 'Hello PortletName' 

This is a great way to get started easily (except that the ability to make a maven project for your portlet is not yet available by default... it is in Liferay IDE 2.0, though... scheduled for December 2012... I can't wait!) The biggest problem with not having a maven build is the lack of versioning for the dependencies. To counter this, I put a pom.xml of my own into the root of the project. I use this pom to manage the dependencies... running 'mvn install' will grab down the proper dependencies, and copy them to the correct folder so that the ant build can find them, then run the ant build. Be sure to run mvn eclipse:eclipse to recreate the .classpath file so that Eclipse can find the new .jar, and refresh your Eclipse project...

My test pom.xml is as follows (I am working on a OpenLayers project right now... just add whatever dependencies you need to this pom.  You can find the appropriate dependencies sections on the Vaadin site under each respective Add-On:
 <project xmlns="http://maven.apache.org/POM/4.0.0"  
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0  
                           http://maven.apache.org/xsd/maven-4.0.0.xsd">  
      <modelVersion>4.0.0</modelVersion>  
      <groupId>com.mdahatter</groupId>  
      <version>1.0-SNAPSHOT</version>  
      <artifactId>local-buzz</artifactId>  
      <name>Local Buzz</name>  
      <packaging>pom</packaging>  
      <dependencies>            
           <dependency>            
                 <groupId>com.vaadin.addon.chameleon.ChameleonTheme</groupId>  
                 <artifactId>vaadin-chameleon-theme</artifactId>  
                 <version>1.1.0</version>  
           </dependency>  
           <dependency>  
                <groupId>org.vaadin.vol</groupId>  
                <artifactId>openlayers-wrapper</artifactId>  
                <version>1.0.0</version>  
           </dependency>  
           <dependency>  
                  <groupId>org.vaadin.addons</groupId>  
                  <artifactId>toolkit-productivity-tools</artifactId>  
                  <version>1.2.0</version>  
           </dependency>  
      </dependencies>  
      <build>   
           <plugins>  
                <plugin>  
                     <groupId>org.apache.maven.plugins</groupId>  
                     <artifactId>maven-dependency-plugin</artifactId>  
                     <version>2.3</version>  
                     <executions>  
                          <execution>  
                               <id>copy-dependencies</id>  
                               <phase>package</phase>  
                               <goals>  
                                    <goal>copy-dependencies</goal>  
                               </goals>  
                               <configuration>  
                                    <outputDirectory>./docroot/WEB-INF/lib</outputDirectory>  
                                    <overWriteReleases>true</overWriteReleases>  
                                    <overWriteSnapshots>true</overWriteSnapshots>  
                                    <overWriteIfNewer>true</overWriteIfNewer>  
                               </configuration>  
                          </execution>  
                     </executions>  
                </plugin>  
                <plugin>  
                     <groupId>org.codehaus.mojo</groupId>  
                     <artifactId>exec-maven-plugin</artifactId>  
                     <version>1.2</version>  
                     <executions>  
                          <execution>  
                               <id>Run Ant Build</id>  
                               <phase>install</phase>  
                               <goals>  
                                    <goal>exec</goal>  
                               </goals>  
                               <configuration>  
                                    <executable>ant</executable>  
                               </configuration>  
                          </execution>  
                     </executions>  
                </plugin>  
           </plugins>  
      </build>  
      <repositories>  
           <repository>  
                <id>vaadin-addons</id>  
                <url>http://maven.vaadin.com/vaadin-addons</url>  
           </repository>  
      </repositories>  
 </project>