Showing posts with label Portlets. Show all posts
Showing posts with label Portlets. Show all posts

Monday, 23 January 2012

LIferay - new liferay project "Failed while installing Liferay Portlet 6.0"

While attempting to create my first Liferay project I found my self facing an error.
"Failed while installing Liferay Portlet 6.0. Most of the project seemed to be present but there were missing xml files and a missing icon. Being dumb and keen I perservered. The portlet would deploy but nothing worker right.
So having deleted everything I came in on the monday morning to start again.
A quick bit of research shows the following:
  • Installing Eclipe for Java developers does not include the web development tools;
    So a dynamic web site will not work;
  • Installing the Liferay IDE plugin fetches you the latest version of the tools which allows a dynamic web site 2.x to 3.0;

When a dynamic web project  is created, various information is assembled to specify the type of project, add standard libraries, set compiler options, control publishing tasks, set the build path and/or add an annotation processor. This information is specified by choosing facets during project creation. Facets can also be added and deleted from a project after its initial creation. To edit a project's facets, select Project > Properties > Project Facets.
Facets have version numbers. Not all facet version numbers can be changed (e.g., a facet available in only one version of software can not have other version numbers). Some facet version numbers are inter-dependent (e.g., if you choose the facet Java Annotation Processing, you must also have Java version 5.0 selected since Java versions 1.3 and 1.4 did not support annotation processing).
Doing some more research I discovered that the version number was related to the Servlet API version. A snippet from Wikipedia: http://en.wikipedia.org/wiki/Java_Servlet


Servlet 3.0December 2009JavaEE 6, JavaSE 6Pluggability, Ease of development, Async Servlet, Security, File Uploading
Servlet 2.5September 2005JavaEE 5, JavaSE 5Requires JavaSE 5, supports annotations
Servlet 2.4November 2003J2EE 1.4, J2SE 1.3web.xml

Tomcat 7 will support 2.2 and 3.0 (See ...) and if you attempt to create a standard dynamic web project everything goes fine.
So what to do .....

While creating your project click the Advance project configuration... button link.


After selecting this option select a lower version of the servlet protocol. Postings on the Liferay forum seem to indicate that 2.5 and 3.0 do not work.So choose 2.4 ...

This seems to work a treat!

Friday, 20 January 2012

Installing and setting up Liferay on Tomcat 7

Liferay is distriuted under a LGPL licence.

Author used Tomcat 7.0.23  & Liferay 6.1.0
This is an abreviated version of a very usefull article on installing LifeRay into an existing Tomcat container. (See...)
  • Ensure Tomcat already runs and has no other webapps;
  • Install the Liferay Dependencies bundle in your Tomcat installation (See...);
    There are three JARs and they go in tomcat-x.x.x/lib/ext.If you do not have the ext directory, create one. This folder is for JARs that are loaded by the Bootstrap class loader.
  • Add " Java transaction manager " jta.jar (Available here; download class files and rename the ZIP file jta.jar.) (Software License Agreement);
  • Add mail.jar (Available here; located in root of the downloaded ZIP file.) (JavaMail License Agreement);
  • Delete all the contents in /ROOT;
  • Move the files from the .war to the now empty ROOT folder. The simplest way to do this is to open it with an archiver program such as 7zip or WinRAR, then copy/extract all of the files into ROOT. 
  • Add a file version.txt to the folder as a reminder of the version of LifeRay in use.
    ie. "liferay-portal-6.1.0-ce-ga1-20120106155615760"
  • Edit the file and add the line
    set "JAVA_OPTS=%JAVA_OPTS% -Xmx1024m -XX:MaxPermSize=256m"
    
    Somewhere near the top.;
  • Inside eclipse change the VM tomcat settings for the Sysdeo plugin.
    This is under Window-->Tomcat-->JVM Settings [Append to JVM Parameters][Add]...
    -Xmx1024m 
    -XX:MaxPermSize=256m
Which may not work at this time as there do not seem to be enough JARs in the ext folder.

OR
  • This version comes with data and a set of plugins which appear as webapps;
  • Start up Tomcat and the start up triggers a browser window titled "Basic Configuration";
  • Set the portal name;
  • Set the default language to English (UK);
  • Don't forget to set up the admin user;
  • Finish the configuration;
  • The configuration will be stored in a file called portal-setup-wizard.properties located at the same level as the tomcat server folder;
  • Click Goto my Portal and see the portal;
  • Shut down tomcat and edit the tomcat server.xml  file change "<Connector port="8080"" to "<Connector port="80"";
  • Re-start tomcat to check the new port;
  • Next we need to set up the email client.Liferay's default configuration looks for a mail server on the same machine on which Liferay's running, and it tries to send mail via SMTP to this server. If this is not your configuration, you'll need to modify Liferay's defaults. To do this, you'll use a portal-ext.properties file.
    The file that is used to override the configuration is portal-ext.properties. This file should be created in your Liferay Home folder.

Setting up Eclipse check list (Part 3) - Plugins

Plugins are probably very personal to what you are doing.
My set is for:
  • Java Development;
  • JSP tomcat development;
  • PHP development;
  • Webpage development;
  • Portal development; 
I have installed the plugins in the following order:

JSP tomcat development
  1. Download Sysdeo Eclipse Tomcat Launcher plugin.
    Version 3.3 seems best.
    Just follow their isntructions which basicly means unzip into - Eclipse_Home/dropins;
    Add the DevloaderTomcat7.jar to the <tomcat home>/lib folder. (Do not be tempted to placed them in the ext folder as it will not work).
    On restart you should see the tomcat icons:

    Under Windows-->Preferences; Tomcat point the Tomcat Home to your desired version of tomcat.
    Under Windows-->Preferences; Tomcat set up "Contect declaration mode" to be Context files as this prevents all the messy editing of a single server.xml file;
    Under Windows-->Preferences; Tomcat-->JVM Settings point the JVM to your desired version JRE. I suggest that this is set to be the JDK you installed earlier.
    Test the whole thing with a Java project containing a dummy bean class;
    Create a web project with a JSP that targets the bean;
    Link the projects;
    Set up the devloader's paths under "Project"-->Properties ; Tomcat-->DevLoader Classpath;
    A nice article is here in case my short-hand check list is too breif.
PHP development
It is fun to have PHP running in Tomcat and not too hard to achieve. Especially if you follow the instructions at PHP/Java Bridge or even here.
My notes on this are located here.
  1. Don't forget to Install and configure PHP on your machine or it won't work at all - duh!;
  2. Set up Tomcat to serve PHP by default.
  3. Create a new Tomcat project;
  4. Add a index.php file with this contents:

    <?php phpinfo();?>

  5. Start the server up and browse to it you should get the PHP info as a HTML page.
  6. Next setup debugging. This is detailed in the later post (here...)
Setting up PHP under Tomcat can be relatively straight forwards. However at some point you are going to want to run some form of web CMS. My current suggestion is ModX. (See...)

Portal development
I am doing portal development with Liferay so first you need to down load the Portlet SDK from their down load site.
A full set of install & configuration options are available on the LifeRay IDE setup pages or follow my short hand.
  1.  Down load the Liferay including tomcat and set it up as a stand-a-lone Tomcat instance (Liferay 6.1.0 contains tomcat 7.0.23).
    I don't know if it will run PHP out of the box more to add later.
    And the Sysdeo Devloader
    I installed my life ray to C:\development\java\tomcat\liferay-portal-6.1.0;
  2. Create a new eclipse workspace to preserve all the raw Tomcat setings and reconfigure with <liferay-portal-home>/tomcat-7.0.23 as your tomcat-home location;
    Don't forget to import all your Java preferences!
  3. Add under Windows-->Preferences; Tomcat-->JVM Settings

    -XX:MaxPermSize=512m
    -Xmx2048m

  4. Test your Liferay portal starts in Eclipse;
    (Start up time can be amlost 2mins 12000ms);
  5. Install the SDK
    Pick the latest comunity version of the Portlet SDK. Mine went into my java libs folder (C:\development\java\libs\liferay\6.1.0). Next add the Liferay IDE via the eclipse plugin installer which is under Help-->Install New Software ; Add. button to open Add Site dialog.Type in "Liferay IDE" for name and use the Indigo release stable URL - http://releases.liferay.com/tools/ide/eclipse/indigo/stable/.
    This comes with a large number of IDE dependencies so it is a good one to install after Sysdeo.
    If it has loaded correctly then it should add icons to your eclipse toolbar.
  6. Under Windows-->Preferences;Liferay -->Installed Plugin SDKs add the installed SDK (Mine is in :\development\java\libs\liferay\6.1.0);
  7. Under Windows-->Preferences;Liferay; Create a new Runtime environment  and choose "Liferay v6.1 CE (Tomcat 7)" ;
    Which in turn will want to know where tomcat is, (ie. C:\development\java\tomcat\liferay-portal-6.1.0\tomcat-7.0.23);
    This seems to add the correct libs when creating an addin. (???)
  8. Follow through and add a server configuration to handle this set up;
    Or it seems that the test packages will not operate correctly as there must be a target runtime to link to.




(Prev - Java preferences)

Setting up Eclipse check list (Part 2) - Java Preferences (Codetemplates.xml)

See original article


<?xml version="1.0" encoding="UTF-8" standalone="no"?><templates><template autoinsert="false" context="overridecomment_context" deleted="false" description="Comment for overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name="overridecomment">/**
 * Overriden method ${enclosing_method}.
 * ${todo} Document why ${enclosing_type}.${enclosing_method} is overridden.
 *
 * ${tags}
 * ${see_to_overridden}
 */</template><template autoinsert="false" context="filecomment_context" deleted="false" description="Comment for created Java files" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.filecomment" name="filecomment">/**
 * ${project_name} - ${type_name}
 * Copyright (c) ${year} by EMBED PLAYSAFE
 * ALL RIGHTS RESERVED
 *
 * Created by ${user} on ${date}.
 */

</template><template autoinsert="false" context="gettercomment_context" deleted="false" description="Comment for getter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name="gettercomment">/**
 * Getter method for ${bare_field_name} of type ${field_type}.
 * May instantiate ${bare_field_name} if it does not exist.
 * @return the ${bare_field_name} or &lt;code&gt;null&lt;/code&gt; if not present.
 */</template><template autoinsert="false" context="fieldcomment_context" deleted="false" description="Comment for fields" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name="fieldcomment">/**
 * ${todo} Comment ${field} or type ${field_type}.
 */</template><template autoinsert="false" context="constructorcomment_context" deleted="false" description="Comment for created constructors" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name="constructorcomment">/**
 * ${todo} Comment constructor for ${enclosing_type}.
 *
 * ${tags}
 */</template><template autoinsert="false" context="settercomment_context" deleted="false" description="Comment for setter method" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.settercomment" name="settercomment">/**
 * Setter for ${bare_field_name} of type ${field_type}.
 *
 * @param ${param} the ${bare_field_name} to set
 */</template><template autoinsert="false" context="methodcomment_context" deleted="false" description="Comment for non-overriding methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name="methodcomment">/**
 * ${todo} Comment method ${enclosing_method} in ${enclosing_type}.
 *
 * ${tags}
 */</template><template autoinsert="false" context="typecomment_context" deleted="false" description="Comment for created types" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.typecomment" name="typecomment">/**
 * ${todo} Comments for ${type_name}.
 *
 * @author ${user}
 * @version 1
 *
 * ${tags}
 */</template><template autoinsert="false" context="delegatecomment_context" deleted="false" description="Comment for delegate methods" enabled="true" id="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name="delegatecomment">/**
 * Delegate Method
 * ${tags}
 * ${see_to_target}
 */</template></templates>

Monday, 16 January 2012

Liferay Spring integration

Getting the Spring context when running LifeRay

Spring context per WAR file 
First, update your web.xml file to load the context:

<web-app>
  <description>Financial Quotes Portlet Application</description>
 
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/YourSpringContextFile.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  .....
</web-app>
 Then as you can see from the web.xlm file, you are putting your spring context file in the WEB-INF directory of your WAR file.

Now, to get a bean, you do the following. I usually create a helper/utility class to help fetch beans, but here it is in a nutshell:

PortletContext context = getPortletContext();
WebApplicationContext springContext = (WebApplicationContext)   
                 context.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
Object beanObject = springContext.getBean("yourBeanName");
 the beanObject should be cast to your Spring bean interface/class. Then you can use it. If you are getting the bean from a servlet, its pretty much the same except you use a ServletContext instead of a PortletContext.

Various Spring Contexts
Spring provides various contexts depending on how you are using spring: an application context (for apps such as stand-alone apps, ie desktop applications that don't run in a web container), web applicatoin contexts and portlet contexts.
The example given included updated the web.xml file, which is a web-level configuration file, not specific to portlets.
There is a PortletApplicationContext. Spring has a Portlet MVC framework that you can use with your JSR-168 portlets.
Where is this Spring file located? If its in a different web application, this can be problematic. For instance, if this file is in lferay's ROOT web application, it will be in a different classloader than your web application (assuming you are deploying a different WAR file).





Read also http://www.liferay.com/community/forums/-/message_boards/message/2134782

LifeRay vs ModX

Comparing two widly different products based on there Web Content Management features:


   

Liferay Portal

   

MODx

Recommended Web Content Management Systems (CMS)


Product Details

Product NameLiferay ​PortalMODx
Company / DevelopersLiferay,​ ​IncMODx ​team
Latest Stable ReleaseLiferay ​Portal ​6.​0.​6MODx ​1.​0.​2
Application Server
      
Apache
J2EE
Apache
      J2EE
Price$​0$​0
Operating System
      Platform Independent
      Platform Independent
License
      GPL
LGPL
GPL
      LGPL
Programming Language
Java
      PHP
      Java
PHP
Database
DB2
Microsoft SQL Server
MySQL
Other
PosgreSQL
      DB2
      Microsoft SQL Server
MySQL
      Other
      PosgreSQL
OverviewLiferay Portal Web Content Management System by Liferay, Inc is distributed through a LGPL license. It runs on a J2EE server with support for a DB2, Microsoft SQL Server, MySQL, Other, PosgreSQL database and is in the Java programming language.MODx Web Content Management System by MODx team is distributed through a GPL license. It runs on a Apache server with support for a MySQL database and is in the PHP programming language.

Website

WebsiteLiferay Portal  (liferay.com)MODx  (modxcms.com)

Features

Root Access
Shell Access
Authentication Type
Kerberos
LDAP
NTLM
Pluggable
      Kerberos
LDAP
      NTLM
Pluggable
Page Caching
Database Replication
FTP SupportLimited
XHTML Compliant
UTF-8 Support
Database ReportsCosts ​Extra
Metadata
Friendly URLs
Yes
Yes
URL Rewriting
Yes
Yes

Other Features

Content ApprovalFree ​Add ​On
VersioningFree ​Add ​On
Commercial Support/TrainingLimited
Drag-N-Drop ContentLimited
Subscriptions
Load Balancing
Web StatisticsLimited
Web Services Front-end
Yes
Yes
RSS

More DetailsMore Details

From http://web-cms.findthebest.com/compare/5-42/MODx-vs-Liferay-Portal