Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Liferay 6.x Portal Enterprise Intranets Cookbook
Liferay 6.x Portal Enterprise Intranets Cookbook

Liferay 6.x Portal Enterprise Intranets Cookbook: Over 60 hands-on recipes to help you efficiently create complex and highly personalized enterprise intranet solutions with Liferay Portal 6.x CE

eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Liferay 6.x Portal Enterprise Intranets Cookbook

Chapter 1. Installation and Basic Configuration

In this chapter, we will cover the following topics:

  • Quick running Liferay on a Tomcat bundle
  • The Liferay setup wizard and first login
  • Setting up the developer's environment
  • Creating a custom portlet

Introduction

Liferay is the market's leading provider of open source portal solutions. It provides a solid platform to serve our site to all clients. It is difficult to say what Liferay is. On the one hand, Liferay is a great content-management system, but on the other hand, it provides many tools for collaboration and communication between users. It can also be a social platform with many functionalities, such as wall, message board, chat, and many others. Furthermore, it is a portlet container that is JSR-168 and JSR-286 compliant. Java Specification Requests (JSRs) describes final specifications for the Java platform. A portlet is a small web application that produces fragments of HTML code that are aggregated into a portal. JSR-168 and JSR-286 specifications standardize how portlets interact with portlet containers. These specifications also describe a standard application programming interface for Java portlet development. In other words, Liferay is only responsible for aggregating the set of portlets that are to appear on any particular page. This approach gives users a great tool to organize and customize portlets in order to build whole portals, social platforms, or intranets. Within Liferay, a portal is composed of a number of portlets, which are self-contained interactive elements that are written to a particular standard. A number of publications describe Liferay's advantages. In this book, we will try to delve deeper into Liferay's architecture and its functionalities.

The primary purpose of this chapter is to give you an insight about Liferay's installation and management with basic configuration. We realize that there are many ways to download, compile, install, and run Liferay Portal. Our main purpose is to provide some clear and basic information about the starting package on which we will rely and work. This chapter explains the main processes that are performed on every compiling action or on every startup action.

Liferay Portal is distributed in two different editions:

  • Liferay Portal Community Edition (CE): This is a free and open source version of Liferay
  • Liferay Portal Enterprise Edition (EE): This is a commercial offering that has Liferay engineers, support, and services

This book is based on the Liferay Portal Community Edition (CE) version with the newest release, which is 6.2.

To start the journey with Liferay, there are a few starting points that contain a lot of useful information, which are as follows:

URL

Description

http://www.liferay.com/

Official Liferay site

http://www.liferay.com/downloads/liferay-portal/available-releases

Place with available releases

http://www.liferay.com/documentation/liferay-portal/6.2/user-guide and https://dev.liferay.com/

User guides and documentation

http://svn.liferay.com/repos/public/portal

Old-fashion repository of Liferay code.

  • Login: Enter guest in this field
  • Password: This field is to be left empty

https://github.com/liferay/liferay-portal/tree/6.2.x

[Recommended] GitHub repository

Tip

Liferay introduced 7.0 version, which will be released on September 2015. Do not check out Liferay sources from the trunk. There are many changes between 6.2 and the trunk version. In the 7.0 version, Liferay will provide OSGi integration and many new features. These new features help users and developers achieve a whole bunch of out-of-the-box functionalities (for instance, Elasticsearch as a search server based on the Lucene framework).

Quick running Liferay on a Tomcat bundle

The simplest way to run Liferay is to download a specific bundle from the Liferay official site. A Liferay bundle is just a compressed archive that contains all that is needed to host the Liferay Portal. A bundle consists of a Java-based application server and the deployed Liferay Portal core application. Liferay provides these bundle runtimes with different application servers (that is, Tomcat, JBoss, Geronimo, and so on) so that you can use any one based on your choice. This method is recommended for people who just want to run Liferay Portal, look at its functionalities, and configure their site using the GUI. In this recipe, you will learn the art of setting up Liferay on Tomcat and the MySQL database engine.

Getting ready

First, make sure that JRE or JDK is properly installed. Type the following command line:

$ java -version

The result should be similar to this:

$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode).

Also, check out the Java SDK version. Liferay recommends Java 7 or later.

Moreover, determine whether the MySQL server installation is done:

$ mysql --version

As a result, the actual installed version should be displayed. Here is an example:

mysql  Ver 14.14 Distrib 5.5.34, for debian-linux-gnu (x86_64)

Also, check out the MySQL version. We recommend 5.5 version or later.

How to do it...

In order to run Liferay on a Tomcat bundle, follow these steps:

  1. Create a database with the name lportal:
    CREATE DATABASE lportal CHARACTER SET utf8 COLLATE utf8_general_ci;
    grant all privileges on lportal.* to '{USERNAME}'@'%' identified by 'PASSWORD';

    Make sure that the MySQL user has permissions to create tables.

  2. Download the correct Liferay version on the Tomcat bundle from http://www.liferay.com/downloads/liferay-portal/available-releases.
  3. Unzip the downloaded archive.
  4. Go to the extracted folder liferay-portal-6.2-ce-ga2. This path will be called ${liferay.home} folder.
  5. Go to the ${liferay.home} folder and create a file called portal-ext.properties.
  6. Edit portal-ext.properties and set the database properties:
    jdbc.default.driverClassName=com.mysql.jdbc.Driver
    jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
    jdbc.default.username={USERNAME}
    jdbc.default.password={PASSWORD}
  7. Find the Tomcat folder and go to the tomcat-7.0.42/bin/ location.
  8. Run the ./startup.sh script (startup.bat for Windows OS) and look into the tomcat-7.0.42/logs/catalina.out log.
  9. In a browser, type http://localhost:8080 location. By default, Tomcat listens on port 8080. It should render the Liferay setup wizard by default. This wizard will ask for basic information, such as, portal name, default language, and administrator user details.

How it works...

Running the Liferay Portal from a prepared bundle is quite an easy task to accomplish. However, it is worth knowing what exactly happens when Tomcat is being started. Take a brief look at the catalina.out log and try to examine it line by line.

Loading the configuration descriptor

The first thing is to deploy ROOT.xml. In our catalina.out file, there is a line present, which is shown as follows:

INFO: Deploying configuration descriptor /home/piotr/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/conf/Catalina/localhost/ROOT.xml

It means that the configuration file turns on the crossContext attribute in Tomcat 7. This setting is required because Liferay is a portlet container. Hence, it is an application that should have access to other applications called portlets. The Apache Tomcat documentation says:

"Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host."

Loading system properties and portal properties

The next few lines of the logfile show portal properties and system properties that are loaded from specific locations:

Loading jar:file:/home/piotr/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
Loading jar:file:/home/piotr/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/system.properties
Loading jar:file:/home/piotr/liferay-portal-6.2-ce-ga2/tomcat-7.0.42/webapps/ROOT/WEB-INF/lib/portal-impl.jar!/portal.properties
Loading file:/home/piotr/liferay-portal-6.2-ce-ga2/portal-ext.properties

The main configuration file for Liferay Portal is portal.properties, which contains a detailed explanation about the properties that it defines. There are at least three possible ways to override portal.properties. There is a functionality to put portal-ext.properties in the ext plugin, in the ${liferay.home} directory, or in portal-setup-wizard.properties. But which file is the most important? The answer is placed in portal.properties file. The default read order is portal.properties, portal-bundle.properties, portal-ext.properties, and then portal-setup-wizard.properties:

    include-and-override=portal-bundle.properties
    include-and-override=${liferay.home}/portal-bundle.properties
    include-and-override=portal-ext.properties
    include-and-override=${liferay.home}/portal-ext.properties
    include-and-override=portal-setup-wizard.properties
    include-and-override=${liferay.home}/portal-setup-wizard.properties

Detecting the database and database dialect

The next step is to recognize the database's dialect:

12:35:47,469 INFO  [localhost-startStop-1][DialectDetector:71] Determine dialect for MySQL 5
12:35:47,504 INFO  [localhost-startStop-1][DialectDetector:136] Found dialect org.hibernate.dialect.MySQLDialect

Liferay supports many database engines, such as DB2, Derby, Hypersonic, Ingres, MySQL, Oracle, P6Spy, PostgreSQL, and Sybase. The default database is Hypersonic, which stores all data in the ${liferay.home}/data/hsql/lportal directory. This is a good option for developers who want to run JUnit tests, which modify data by testing the persistence layer or business process.

On every restart, Liferay tries to get the build number (Liferay version) from the Release_ table. If this table doesn't exist, it calls ReleaseLocalService.createTablesAndPopulate().

If it is not possible to get the build number, Liferay logs the following information:

WARN  [localhost-startStop-1][ReleaseLocalServiceImpl:171] Table 'lportal.Release_' doesn't exist

The createTablesAndPopulate method runs following scripts:

  • liferay-portal/sql/portal-tables.sql: This creates the required tables
  • liferay-portal/sql/portal-data-common.sql: This adds the default data
  • liferay-portal/sql/portal-data-counter.sql: This inits the unique key generator
  • liferay-portal/sql/portal-data-release.sql: This sets the release date
  • liferay-portal/sql/indexes.sql: This adds database indexes
  • liferay-portal/sql/sequences.sql: By default, this file is empty.

Apart from creating tables and populating data, Liferay triggers the VerifyProcess mechanism. This process will run on every startup to verify and fix any integrity problems found in the database. This is the perfect place for developers to add custom code to check the integrity of specific cases.

Starting the autodeploy scanner and deploying plugins

The last step is initializing the autodeploy and the hotdeploy listeners. In general, these mechanisms install all the plugins into the Tomcat container and register them as portlets, hooks, themes, and so on. In particular, there are at least three deploying approaches: sandbox deploy, autodeploy, and hotdeploy.

Note

By default, Liferay uses the autodeploy and hotdeploy listeners. In fact, sandbox can currently deploy only themes and portlets.

The autodeploy mechanism is responsible for listening on a specific directory to install on-the-fly new plugins and copying them into the Tomcat hotdeploy process. A definition of that directory is placed in portal.properties, and by default, it is in the deploy folder:

auto.deploy.deploy.dir=${liferay.home}/deploy

Every type of plugin has its own autodeploy mechanism. This mechanism runs all the necessary steps to install it correctly in the Liferay container. In simple terms, the autodeploy mechanism generates the web.xml file and adds the required libraries to specific plugins. Definitions of these classes are placed in the portal.properties file with an auto.deploy.* prefix. Each class extends BaseAutoDeployListener.

The second process, hotdeploy, is responsible for registering plugins in Liferay. There are many steps, such as creating database tables, setting preferences, registering Spring application contexts, and so on. Of course, each step depends on the type of plugin. In portal.properties, there are definitions for each type of class:

hot.deploy.listeners=
com.liferay.portal.deploy.hot.PluginPackageHotDeployListener,
com.liferay.portal.deploy.hot.SpringHotDeployListener,
com.liferay.portal.deploy.hot.ServletContextListenerHotDeployListener,
com.liferay.portal.deploy.hot.ExtHotDeployListener,
com.liferay.portal.deploy.hot.HookHotDeployListener,
com.liferay.portal.deploy.hot.JSONWebServiceHotDeployListener,
com.liferay.portal.deploy.hot.LayoutTemplateHotDeployListener,
com.liferay.portal.deploy.hot.PortletHotDeployListener,
com.liferay.portal.deploy.hot.SocialHotDeployListener,
com.liferay.portal.deploy.hot.ThemeHotDeployListener,
com.liferay.portal.deploy.hot.ThemeLoaderHotDeployListener,
com.liferay.portal.deploy.hot.MessagingHotDeployListener

Tip

In the deployment process, the Liferay deployer modifies the web.xml file, adds specific dependencies, and packs it again. Ensure that you do not copy the WAR file directly to the Tomcat webapps folder. If you do so, the plugin will not work.

There's more...

Often, enterprises have an established Java EE infrastructure upon which they would like to install Liferay. You must consider also the enterprise's security policies. These policies sometimes prevent the download and installation of the Tomcat bundle into a location of your choice. In this situation, a bundle will not suffice, and you have to manually install Liferay from its WAR archive into an already existing Apache Tomcat application server.

There are six steps to achieve this goal. They are as follows:

  1. Copy specific JAR files and dependencies to the Tomcat global lib folder, $TOMCAT_HOME/lib/ext.
  2. Enable crossContext by adding the ROOT.xml file to the $TOMCAT_HOME/conf/Catalina/localhost folder.
  3. Set custom $JAVA_OPTS parameters in the $TOMCAT_HOME/bin/setenv.sh file:
    JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF8 -Dorg.apache.catalina.loader.WebappClassLoader.ENABLE_CLEAR_REFERENCES=false -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"
  4. Update the common.loader property located in $TOMCAT_HOME/conf/catalina.properties with the following lines of code:
    common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/lib/ext,${catalina.home}/lib/ext/*.jar
  5. Specify the URI encoding as UTF-8 in $TOMCAT_HOME/conf/server.xml as follows:
    <Connector port="8080" protocol="HTTP/1.1"
      connectionTimeout="20000"
      redirectPort="8443" URIEncoding="UTF-8" />
  6. Deploy Liferay Portal using Tomcat manager or manually put the WAR archive into the $TOMCAT_HOME/webapps folder. The WAR file is available at http://www.liferay.com/downloads/liferay-portal/available-releases#additional-versions.

Note

More detailed instructions of how to install Liferay on the Tomcat server are available on the official Liferay documentation at https://www.liferay.com/documentation/liferay-portal/6.2/user-guide/-/ai/installing-liferay-on-tomcat-3.

See also

For information about running Liferay on the clustered environment, refer to the Clustering Liferay Portal recipe in Chapter 11, Quick Tricks and Advanced Knowledge, and the Scalable infrastructure recipe in Chapter 12, Basic Performance Tuning. For information about setting the developer's environment, refer to the next recipe.

The Liferay setup wizard and first login

After successfully running Liferay on the Apache Tomcat server, the system asks users to fill some necessary information to complete the setup wizard. This is only a single screen with basic fields, such as administrator name or portal name.

How to do it…

After running Liferay for the first time, the Liferay platform displays the basic configuration form, which looks like this:

How to do it…

To finish installation, it is necessary to fill in the preceding form as follows:

  1. Provide details about Portal:
    • Portal Name: This is the name of the website, for instance, Enterprise Intranets
    • Default Language: This helps in choosing the default language of the portal
    • Add Sample Date: This decides to populate the portal with default data
  2. Provide details about Administrator User:
    • First Name and Last Name
    • E-mail address
  3. Choose the database engine (optional). In the previous recipe, we set properties with a MySql connection.
  4. Confirm the form.
  5. Click on the Go to My Portal button.
  6. Click on the I agree button on the Terms of Use screen.
  7. Fill in the Password Reminder form and confirm the form.

    After confirming the Password Reminder form, you will be able to see and use the main Liferay navigation tools.

Follow these steps to navigate to Control Panel:

  1. Click on the Admin button located on the dockbar menu.
  2. Click on the Control Panel link.

How it works…

After running Liferay for the first time, Liferay needs basic information about the portal, database, and administrator. The database connection was set in portal-ext.properties, and it was described in the previous recipe.

All data which was provided on the portal wizard was stored in the ${liferay.home}/portal-setup-wizard.properties file. The most important settings are described in the following table:

Property name

Description

admin.email.from.name

This describes the name of the administrator.

admin.email.from.address

This is the e-mail address of the administrator.

liferay.home

This is the path to the ${liferay.home} directory. This property is very important and must be set.

setup.wizard.enabled

This flag disables the setup wizard.

After logging in, the user is able to see navigation tools available for authorized users only. Here are the navigation tools:

  • The dockbar menu is located under the top screen edge. The dockbar consist of three buttons:
    • The Admin button that allows us to navigate to the Site Administration and Control Panel sections
    • The My Sites button that lists links to sites that the user is a member of
    • The button with user name and surname that allows us to navigate to user's profile (My Profile), user's dashboard (My Dashboard), user's account (My Account), and also allows the user to log out
  • The fast edition menu is located near the left edge of the screen. The menu consists of the following icons:
    • The Add icon that allows us to add a new page, a new application to the page, or new content
    • The Edit icon that allows us to edit the settings of the currently viewed page
    • The Preview icon that allows us to view the currently viewed page in different resolutions and devices
    • The Edit Controls icon that allows us to hide or show controls of portlets

There's more…

In internal projects such as intranets, user accounts most often are created and managed in external systems, for instance, LDAP. Therefore, it is unnecessary (and sometimes even unacceptable) to allow users to manage their authentication data (for instance, to set a password-reminder query) or ask them to agree to terms of use directly within Liferay. In Liferay, there are many properties that can help customize the first login action, a few of which are as follows:

Property name

Description

terms.of.use.required=false

This turns off the terms of use

terms.of.use.journal.article.group.id and terms.of.use.journal.article.id

This specifies the group ID and article ID that will be displayed as the terms of use

users.reminder.queries.enabled=false

This disables the reminder query functionality

See also

  • For information on adding new users and defining roles and permissions, refer to the Adding a new user recipe in Chapter 3, Working with Liferay User / User Group / Organization
  • Creating and configuring roles and Assigning user roles recipes in Chapter 5, Roles and Permissions
  • For information on the default login page, refer to the Overriding the default login page with the administrator defined page recipe in Chapter 2, Authentication and Registration Process

Setting up the developer's environment

Many developers want to customize Liferay Portal to fit it to a client's requirements. Also, in this book, there will be a number of examples of code, so the setting environment is an important step to start with. Liferay mentions that there are two types of development and two ways to get sources:

  • GitHub: For contributors
  • sourceforge.net: For non-contributors

For the purpose of this book, it is enough to use the non-contributors version only.

Getting ready

The minimal requirements to use Liferay Portal are Java Development Kit (JDK), Apache Ant with 1.7 version or later, and Eclipse IDE Indigo or later. Make sure that the installation is successful by typing the following lines of code:

$ ant -version
Apache Ant(TM) version 1.8.2 compiled on May 18 2012

$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

How to do it...

This recipe is divided into three sections. The first section contains a description of preparatory activities such as downloading Liferay sources or unpacking them. The second one provides a description about the required configuration. The last section focuses on compiling all Liferay sources and deploying them into Apache Tomcat server.

Import sources to the Eclipse IDE

The first step is importing Liferay sources as a project in our IDE. These steps are based on Eclipse IDE. To achieve this, follow these steps:

  1. In ${liferay.home}, create a workspace folder.
  2. Go to http://sourceforge.net/projects/lportal/files/Liferay%20Portal/ and choose the folder with the newest 6.x version. Next, find the file with the prefix liferay-portal-src-* and download it.
  3. Unpack this file into the workspace folder.
  4. Import this project to Eclipse IDE by going to File | Import | General | Existing Projects into Workspace and click on the Next button. On the next screen, select Select root directory and point to the folder with Liferay sources, which is ${liferay.home}/workspace/liferay-portal-src-${VERSION}. To complete this task, click on the Finish button.
  5. After this step, it is necessary to create a folder called /portal-web/test/functional in the project. This actions resolves a warning in the Eclipse IDE with the following message: Build path entry is missing: Liferay-portal-src.6.2-ce-ga2/portal-web/test/functional.

Override app.server.properties

To be compatible with the existing Tomcat, which is placed in the ${liferay.home}/tomcat-7.0.42 folder, change the app.server.parent.dir properties. To achieve this, follow these steps:

  1. Create app.server.${username}.properties in the main folder of the project, which is ${liferay.home}/workspace/liferay-portal-src-${VERSION}.
  2. Override Server directory properties and set a new value:
    app.server.parent.dir=${project.dir}/../../

    It could also be an absolute path to Tomcat's parent folder.

    The ${liferay.home} folder should have the following hierarchy:

      .
      |-data
      |---document_library
      |---hsql
      |---lucene
      |-deploy
      |-license
      |-logs
      |-tomcat-7.0.42
      |---bin
      |---conf
      |---lib
      |---logs
      |---temp
      |---webapps
      |-workspace
      |---liferay-portal-src-6.2-ce-ga2

Compile and deploy

Go to {$liferay.home}/workspace/liferay-portal-src-${VERSION} and compile all Liferay sources using the ant all target in a command line.

Note

In this book, we will use a console approach to compile, deploy, and so on. Liferay provides Eclipse with Liferay IDE. For proper understanding, we will use command line as the main tool.

How it works

It could be a source of criticism that Liferay is managed by Apache Ant instead of Maven, Gradle, or other build-automation tools. As a matter of fact, the Apache Ant tool is sufficient to manage and compile the Liferay core. If someone wants to use Maven, they are free to use it in custom portlets. Liferay offers many archetypes to help create Maven projects for multiple plugins.

Let's take a closer look at the project in Eclipse IDE. There are many folders that contain huge bunches of packages. Let's examine the most important folders with regard to Liferay architecture:

Folder name

Description

Definitions

This contains the dtd and xsd definitions, for instance, the portlet.xml definition or the service.xml definition.

portal-impl

This is the central core of the portal. It implements all the interfaces that are exposed in global lib. Also, it contains model definitions. Never put portal-impl anywhere other than where it came from.

portal-service

This provides the interfaces' definitions, which can be used in custom implementation, for instance hooks, portlets, themes, and so on.

util-bridges

This contains bridges and utilities, which can be helpful to implement custom portlets, such as AlloyPortlet, BSFPortlet, MVCPortlet, and so on.

portal-web

This contains the web application root, which has all the configuration files and view tier.

Let's get back to the compile command, ant all. What exactly happened here? Portal has its own runtime structure. It provides ready-to-use bundles with Tomcat, JBoss, or other application servers. It gives a tool that can build a runtime bundle. In the main build.xml Ant file, there is a definition of Ant target https://ant.apache.org/manual/targets.html:

<target name="all">
  <antcall target="clean" />
  <antcall target="start" />
  <antcall target="deploy" />
</target>

The building process consists of three parts: clean, start, and deploy.

Clean process

The ant clean command performs the following steps:

  • It cleans Java classes under the following folders: classes, portal-service, util-bridges, util-java, util-slf4j, util-taglib, portal-impl, portal-pacl, osgi/bootrstap, portal-web and sql
  • It deletes files with mask *.ear, *.jar, *.war, and *.zip
  • It cleans the work, temp, and logs Tomcat folders and removes the *-hook.xml and *-portlet.xml files from the /conf/Catalina/localhost directory

There are some more steps that clean or delete many configuration files depending on the application server. To understand the processes used in this book, it is not important to know every step and deep cleaning process.

Start process

The ant start target invokes the following tasks:

  • It runs the compile target that compiles sources under the portal-service, util-bridges, util-java, util-slf4j, util-taglib, portal-impl, portal-pacl, and osgi/bootstrap folders
  • It builds a database and rebuilds the hypersonic database
  • It builds themes under the portal-impl folder
  • It calls the jar target that generates JAR's and WAR of the Liferay core

Deploy process

This target is strictly dependent on the application server. In general, this build deploys applications into a specific servlet container or application server. Furthermore, this build creates the required folders or files under ${liferay.home}. The folders that this build creates are as follows:

  • The deploy folder for the hotdeploy process
  • The data folder, which contains binary data, such as document library, Jackrabbit, HSQLDB, or Lucene
  • The ROOT.xml context configuration file in ${app.server.dir}/conf/Catalina/localhost/ and many other tasks depending on the application server

There's more...

As mentioned earlier, it is possible to create a full bundle without manually downloading Tomcat or other application server. There are only two steps in order to achieve this goal:

  • Invoke the ant -buildfile build-dist.xml unzip-tomcat task
  • Invoke the ant all command

It is possible to deploy Liferay on a different application server. There is a whole range of commands that do this:

ant -buildfile build-dist.xml build-dist-geronimo
ant -buildfile build-dist.xml build-dist-glassfish
ant -buildfile build-dist.xml build-dist-jboss
ant -buildfile build-dist.xml build-dist-jboss-eap
ant -buildfile build-dist.xml build-dist-jetty
ant -buildfile build-dist.xml build-dist-jonas
ant -buildfile build-dist.xml build-dist-resin
ant -buildfile build-dist.xml build-dist-tcat
ant -buildfile build-dist.xml build-dist-tomcat

Creating a custom portlet

This recipe is very specific, because it shows how to generate a new portlet, install it on Liferay, and import it to the Eclipse IDE. Many recipes from this book assume that the user knows how to generate a new plugin, such as portlet, hook, or web. We will show you how to generate a new portlet using Apache Maven archetypes. The whole book assumes that you use Apache Maven to compile and deploy new portlets.

Getting ready

In order to correctly generate a new portlet, you need to have the following software stack:

  • Java SDK 1.7 or later
  • Apache Maven, we use 3.0.5 version
  • Eclipse IDE (Kepler or later)

We also assume that you properly set the developer's environment, which was described in the previous recipe.

How to do it…

There are three phases to achieve our goal: generating a new portlet, compiling it, and deploying and importing it to the Eclipse IDE.

Generating a new portlet

The first thing we need to do is to create a Maven project. In order to generate it, follow these steps:

  1. Go to the ${liferay.home}/workspace folder.
  2. Execute mvn archetype:generate -Dfilter=liferay-portlet-archetype.
  3. Choose a number for com.liferay.maven.archetypes:liferay-portlet-archetype. In our list, it is number 1:
    Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
  4. Choose the correct Liferay version. In our example, it will be 6.2.2, with the number 24.
  5. Provide all the required Maven project information as follows:
    Define value for property 'groupId': : com.packtpub.portlet
    Define value for property 'artifactId': : first-portlet
    Define value for property 'version':  1.0-SNAPSHOT: : 
    Define value for property 'package':  com.packtpub.portlet: : 
    Confirm properties configuration:
    groupId: com.packtpub.portlet
    artifactId: first-portlet
    version: 1.0-SNAPSHOT
    package: com.packtpub.portlet
    Y: : y
  6. In our workspace folder, a portlet called first-portlet should be generated.

Compiling the portlet and deploying it

With Apache Maven, it is easy to compile and deploy a portlet. Before invoking the Maven command, users have to set specific properties in the pom.xml file.

  1. Go to the ${liferay.home}/workspace/first-portlet folder and edit the pom.xml file.
  2. Under the <build> section, add the following properties definition:
    <properties>
      <liferay.version>6.2.2</liferay.version>
      <liferay.maven.plugin.version>6.2.2</liferay.maven.plugin.version>
      <liferay.auto.deploy.dir>${liferay.home}/deploy</liferay.auto.deploy.dir>
      <liferay.app.server.deploy.dir>${liferay.home}/tomcat-7.0.42/webapps</liferay.app.server.deploy.dir>
      <liferay.app.server.lib.global.dir>${liferay.home}/tomcat-7.0.42/lib/ext</liferay.app.server.lib.global.dir>
      <liferay.app.server.portal.dir>${liferay.home}/tomcat-7.0.42/webapps/ROOT</liferay.app.server.portal.dir>
    </properties>

    Tip

    Replace ${liferay.home} with the real path to your folders.

  3. Save the pom.xml file.
  4. Build a new project by executing the following command:
    mvn clean install
    
  5. Make sure that your Apache Tomcat is running with Liferay.
  6. Invoke the mvn liferay:deploy command and follow the catalina.out logfile. You should see a similar message:
    [PortletHotDeployListener:343] Registering portlets for first-portlet
    [PortletHotDeployListener:490] 1 portlet for first-portlet is available for use
    

Importing the portlet to the Eclipse IDE

After successfully generating sources by the Maven archetype plugin, the sources of our portlet can be imported to our Eclipse IDE. To import them, follow these steps:

  1. Make sure that you are in the ${liferay.home}/workspace/first-portlet folder.
  2. Run the mvn eclipse:clean eclipse:eclipse command.
  3. Open your IDE and import first-portlet as a project by going to File | Import | General | Existing Projects into Workspace.

How it works…

A portlet project created from com.liferay.maven.archetypes:liferay-portlet-archetype has ready-to-use portlet implementation. In fact, it is very basic, but the entire folder's structure and configuration files are correctly created. Each portlet has four configuration files: portlet.xml, liferay-portlet.xml, liferay-display.xml, and liferay-plugin-package.properties. All of these files are placed in the first-portlet/src/main/webapp/WEB-INF folder.

The portlet.xml file is a portlet descriptor. It contains a portlet definition, such as name, portlet class, and so on.

The liferay-portlet.xml file is a kind of extension of portlet.xml. It is only understood by Liferay Portal. It gives additional information such as portlet's icon, path to the css and js files, and so on.

The liferay-display.xml file tells us in which section our portlet will be available. We will describe it later in the book.

The liferay-plugin-package.properties file is a metric of our portlet. This is a good place to specify version, tags, page URL, author, and license.

Detailed information on portlets is available in the JSR-168 and JSR-286 specification. There are many examples on how to use portlets, how to establish communication between portlets, or what is a portlet request lifecycle.

See also

For more information on portlets, refer to the following recipes:

  • The Creating a role-dependent portlet recipe in Chapter 5, Roles and Permissions
  • The Checking permissions in a custom portlet recipe in Chapter 5, Roles and Permissions
  • The language properties hook recipe in Chapter 11, Quick Tricks and Advanced Knowledge
  • The Using Liferay Service Bus for communication between portlets recipe in Chapter 11, Quick Tricks and Advanced Knowledge
Left arrow icon Right arrow icon

Description

If you are a Java developer or administrator with a technical background and want to install and configure Liferay Portal as an enterprise intranet, this is the book for you. In short, reusable recipes help you realize business goals as working features in Liferay. This book will also give you useful hints on how to easily improve the default functionality of the system and its performance.

Who is this book for?

If you are a Java developer or administrator with a technical background and want to install and configure Liferay Portal as an enterprise intranet, this is the book for you. In short, reusable recipes help you realize business goals as working features in Liferay. This book will also give you useful hints on how to easily improve the default functionality of the system and its performance.

What you will learn

  • Build a corporate knowledge base for all employees in your organization
  • Configure site and page templates for departments in your company
  • Design and implement roles and permissions to fit your organization
  • Define efficient business processes using XML representation
  • Integrate with LDAP, CAS SSO, and Solr search engine
  • Improve your portal with caching, clustering, indexing, searching, and more
  • Use effective taxonomy and folksonomy to organize documents and articles

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 30, 2015
Length: 300 pages
Edition : 1st
Language : English
ISBN-13 : 9781782164296
Vendor :
Liferay Inc.
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 30, 2015
Length: 300 pages
Edition : 1st
Language : English
ISBN-13 : 9781782164296
Vendor :
Liferay Inc.
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 159.97
Liferay Portal Performance Best Practices
$38.99
Liferay Portal 6.x Enterprise Intranets (Update)
$65.99
Liferay 6.x Portal Enterprise Intranets Cookbook
$54.99
Total $ 159.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Installation and Basic Configuration Chevron down icon Chevron up icon
2. Authentication and Registration Process Chevron down icon Chevron up icon
3. Working with a Liferay User / User Group / Organization Chevron down icon Chevron up icon
4. Liferay Site Configuration Chevron down icon Chevron up icon
5. Roles and Permissions Chevron down icon Chevron up icon
6. Documents and Media in Liferay Chevron down icon Chevron up icon
7. Working with Content Chevron down icon Chevron up icon
8. Search and Content Presentation Tools Chevron down icon Chevron up icon
9. Liferay Workflow Capability Chevron down icon Chevron up icon
10. Collaboration Tools Chevron down icon Chevron up icon
11. Quick Tricks and Advanced Knowledge Chevron down icon Chevron up icon
12. Basic Performance Tuning Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(4 Ratings)
5 star 75%
4 star 25%
3 star 0%
2 star 0%
1 star 0%
Jens J Jul 03, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I’m new to Liferay and so I bought this book to get basic and detailed information about this system. I had the goal that after reading this book I will have the knowledge for configuration and administration Liferay.In the first chapters the book describes the topics from the installation to the first Liferay site. It’s really well explained and easy to understand. For me it was easy to do my first Liferay installation. Beside this information I was looking for more knowledge about integrating LDAP. In this book the chapter for authentication and registration has in sum 36 pages. The authors gives step by step instructions and “How it works information”. As a user you can do the configuration and know how it works or what happens in the background. For me it was really informative to go through this chapter.When you a working with Liferay for the first time and you plan to configure the first user you will be in contact with the “user”, “user group” and “organization” structure. For me it was new and I had no idea how they work together or how they are interdependent. But in this book there are good examples to understand how to use these functions in a business environment and find a structure for your own company with the necessary roles and rules.In the following chapters the book covers topics like configuring a new site, creating templates, document management and integration workflows. I like to point out the topics live staging and integrating search functionality. For me both are really interesting and helpful for using Liferay as a portal user.If you are using a system like Liferay you will come to a point where you aren’t satisfied with the system performance. This book has an own chapter for “Basic Performance Tuning”. For me it was interesting to go through it. Beside scalability aspects you will find solutions for typical problems like JVM Garbage collection settings to avoid out of memory exceptions.In sum I really enjoyed reading this book. On one hand I had step by step examples to setup and use Liferay and on the other hand I received really informative background information. All in all I can recommend this book to users who are new or still have knowledge in Liferay.
Amazon Verified review Amazon
Pierpaolo Sep 09, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Firstly it's necessary to observe that something like an encyclopedia should be necessary to properly deal the topic "Liferay Portal". Of course resources around the web are generally useful to solve daily problems but, to be honest, Liferay team needs for further effort (because finding dated or non perfect information is really common).In my mind this book is the right tool for people searching for quick and useful information, without losing the possibility to go in depth on important topics, if necessary.In fact, as any cookbook, it doesn't deal with heavy theoretical aspects, but it goes directly to the point by its great number of recipes. On the other hand, it is very common to find an "how it works" paragraph beside a recipe; it analyses important aspects of the previous recipe(s) steps. In other words: a practice to not-mandatory-theory approach.Obviously not all the topic over Liferay are dealt with, but the book is full of recipes for users, developers, systems experts, etc.To provide several example, it writes of any CMS tool (e.g. collaboration), of users, groups, permissions and documents management, of setup and tuning for production environments, of workflow capabilities, etc...
Amazon Verified review Amazon
Vinay Jul 31, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love this book..Will recommend it to everyonw
Amazon Verified review Amazon
SANTHOSH G May 15, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good for beginners
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.