jAPS 2.0 entando - Instantiate a New Portal - HowTo

Do It The jAPS Way

William Ghelfi

Mantainer 
Chief Interaction Designer
Tzente s.r.l.

Marco Diana

Revamp of the first revision 
Chief Technical Officier
AgileTec s.r.l.

Eugenio Santoboni

Integrations to the first revision 
Chief Solution Engineer
AgileTec s.r.l.

Andrea L. Dessì

Integrations to the first revision 
AgileTec s.r.l.

Legal Notice

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the Appendix entitled "GNU Free Documentation License".

The copyright holders make no representation about the suitability of this Document for any purpose. It is provided “as is” without expressed or implied warranty. If you modify this Document in any way, identify your resulting Document as a variant of this Document.

2011-03-03

Revision History
Revision 1.62011-03-03MEM

Update for jAPS 2.0 entando, version 2.2.0

Revision 1.52010-03-17MEM

Update for jAPS 2.0 entando, version 2.0.10

Revision 1.42009-11-11WG

Update for jAPS 2.0 entando, version 2.0.8

Revision 1.32009-03-13WG

English and docbook adoption

This revision is a Release Candidate

Revision 1.22009-01-03ES, MD, WG

First public release

Abstract

The scope of this document is to introduce the development environment and to provide the guidelines for the extraction of a new instance of jAPS 2.0 entando from the source code hosted at SourceForge; thus obtaining the proper skeleton for the configuration of a new portal, ready to be developed.


Chapter 1. Scope of the document

Introduction

The scope of this document is to introduce the development environment and to provide the guidelines for the extraction of a new instance of jAPS 2.0 entando from the source code hosted at SourceForge; thus obtaining the proper skeleton for the configuration of a new portal, ready to be developed.

Target audience

This document is for the ones who are going to develop a new portal using jAPS 2.0 entando, or at least are pondering about. Thus the preferred target audience are specialists of the presentation layer of web development, and Java developers.

Prerequisites

In order to take the maximum advantage of the present document, it is necessary to have basic knowledge about: the Java platform, the Eclipse IDE, the Apache Tomcat servlet engine, the PosgreSQL DBMS.

Resources

Additional informations may be obtained through the official mailing-lists:

Is it also possible to refer to the documentation found in the:

jAPS 2.0 entando Project - Developer Website

Chapter 2. What is jAPS2.0

jAPS 2.0 entando is an Open Source, professional "Enterprise Accessible Information Platform" that makes easier aggregation, publishing, access, customization and integration of information, services, processes and resources, complying with accessibility requirements of W3C WCAG standards.

jAPS 2.0 entando Platform provides performance, reliability and scalability features typical of enterprise software (“Enterprise”), allows users with disabilities to access and manage information and services ("Accessible"), seeks to simplify content management ("Information") and it can be used as a framework ("Platform") to build vertical applications based on contents (Content Enabled Vertical Application).

Chapter 3. Software Requirements

Software Requirements

The development environment for jAPS 2.0 entando needs some previously installed software. In this chapter you will find the proper instructions.

About Operating Systems

The development environment for jAPS 2.0 entando can be installed in different OSes. In this document we will mainly refer to:

  • GNU/Linux Ubuntu 8.10 (or later)
  • Windows XP

pointing out the differences where needed. It will be rather easy to apply the concepts to different OSes. Before starting the installation under the chosen OS, you should check the existence of the right versions of the following needed software:

Development platform
Java 1.6.10 JDK (or later)
Integrated Development Environment
Eclipse 3.4 Ganymede (or later)
Application Server
Apache Tomcat 6.0.18 (or later)
Database Management System
PostgreSQL 8.3 (or later)
JDBC driver for PostgreSQL
the proper version for JDBC3
(optional) Administration tool for PostgreSQL
pgAdmin III 1.6.3 (or later)

Other versions may also work well with jAPS 2.0 entando. Later in this chapter you will find quick installation procedures for all the software requirements.

jAPS 2.0 entando has been reported of being successfully installed also on Application Server jBOSS 4.2.3 and the following Database Servers: MySql, Oracle 10g, and Hypersonic. In jAPS 2.0 entando (but this is true since version 0.1) you will find only ANSI SQL, so the compatibility with other DBMSes (which of course respect the standard) is expected and promoted.

Installing the JDK

The JDK - Java Development Kit - provides a compiler and other tools for the development in Java, and also the execution environment. The JDK can be downloaded from the SUN website. Please take note of the installation path for later use. After a successful installation you need to perform some configurations, described in the following paragraphs.

For Ubuntu 8.10 it is highly recommended to use the package sun-java6-jdk included in the multiverse repository.

Configuration: Microsoft Windows XP

You need to configure the JAVA_HOME environment variable, setting the installation path saved as suggested in the previous paragraph.

JAVA_HOME

The setting of the JAVA_HOME environment variable

  • Right mouse button on My Computer, then choose Properties
  • Choose the Advanced tab and press the Environment Variables button
  • In the System variables box, press the New button and set the variable as showed in the Figure

Configuration: Linux

In order to instruct the system to use the right Java subsystem, you have to run the following shell command:

wiz@id:~$ sudo update-alternatives --config java
[sudo] password for wiz: 

There are 2 alternatives for 'java'.

  Selection    Alternative
-----------------------------------------------
 +        1    /usr/lib/jvm/java-6-openjdk/jre/bin/java
*         2    /usr/lib/jvm/java-6-sun/jre/bin/java

Press return for default[*] value, or insert the selection number
 				

and choose the right version from the available ones (which as said before is the SUN one). You can then check the configuration with the command:

wiz@id:~$ java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
				

Eclipse IDE installation

Eclipse is an open source integrated development environment, which you can download from the official site. The required version is the one called [Eclipse IDE for Java EE Developers], version 3.4 Ganymede or later.

To install Eclipse you just have to extract the package in the preferred directory and run the eclipse executable.

Ubuntu 9.10 comes with a working Eclipse 3.5 Galileo. You will need to manually add the software repositories and install the plugins needed for J2EE development, though.

Starting for the first time, Eclipse will ask you to create a directory called workspace. Accept; that will be the directory under which Eclipse will store all of your projects.

PostgreSQL and pgAdmin III installation

Installation: Microsoft Windows XP

You can download PostgreSQL from the official site. The suggested version is 8.3. It is available an installer (pgInstaller) wich provides an installation wizard.

During the installation you will be asked to choose a characted encoding: choose UTF8. Please also take carefully note of the chosen credentials (username and password).

Usually the installer for Windows comes with pgAdmin III. If it doesn't seem to be installed after the wizard finishes its job, you can download pgAdmin III from its official site.

After the installation, do all the configurations explained in a proper paragraph later in this document.

Installation: Linux

Installing under Ubuntu 8.10 is just a matter of doing an:

wiz@id:~$ sudo apt-get install postgresql postgresql-client postgresql-contrib pgadmin3
					

PostgreSQL is in the main repository, and pgAdmin III in the universe one.

After the installation, run the following commands in order to assign password to the postgres user, and then do all the configurations explained in a proper paragraph later in this document.

wiz@id:~$ sudo su - postgres
postgres@id:~$ psql
Welcome to psql 8.3.6, the PostgreSQL interactive terminal.

Type:  \copyright for distribution terms
       \h for help with SQL commands
       \? for help with psql commands
       \g or terminate with semicolon to execute query
       \q to quit

postgres=# alter user postgres with password 'postgres';
ALTER ROLE
postgres=# \q
postgres@id:~$ exit
logout
wiz@id:~$ 
				

Preparing the database

Now it's time to add an user to the database, which you will use for jAPS 2.0 entando. Launch pgAdmin III and follow these instructions:

  • Connect to the database with username postgres and password postgres (you may have to add a connection using File then Add server...)
  • Right mouse button on Login Roles, choose New Role
  • Set both the username and the password to agile, check the Can create databases privilege setting, confirm with Ok.

Apache Tomcat installation

You can download Apache Tomcat from the official site. The suggested version is 6.0.18. We recommend you to download Apache Tomcat in the form of a compressed archive.

To install Tomcat you just have to extract the package in the preferred directory and run the startup.sh (Linux) or startup.bat (Windows) executable.

Example 3.1. Tomcat: installation directory under Linux OS

/opt/tomcat6


Example 3.2. Tomcat: installation directory under Windows

C:\tomcat6


Please notice that for our chosen development environment and best practices, we only need Tomcat correctly installed in our system but we need it not to run except for the cases you will find later in this document.

Apache Tomcat setup

You have to setup URI encoding for the Tomcat Connectors and enable the automatic trimmer for the JspServlet

Connectors URI encoding

You have to edit this file: server.xml

Looking for the tag Connector, you'll find something like this for port 8080:

<Connector port="8080" protocol="HTTP/1.1" 
	connectionTimeout="20000" 
	redirectPort="8443" />
					

and something like this for port 8443

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
	maxThreads="150" scheme="https" secure="true"
	clientAuth="false" sslProtocol="TLS" />
					

You have to add a new attribute URIEncoding="UTF-8" to the connector tags.

So you'll have in your file server.xml

<Connector port="8080" protocol="HTTP/1.1" 
		connectionTimeout="20000" 
		redirectPort="8443"
		URIEncoding="UTF-8"/>
					

and for port 8443

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
	maxThreads="150" scheme="https" secure="true"
	clientAuth="false" sslProtocol="TLS"
	URIEncoding="UTF-8"/>
					
Trim spaces

Edit the file web.xml in your tomcat installation directory.

Search for <servlet-name>jsp</servlet-name>, and write inside the tag servlet new init param. See example below.

Example 3.3. Enable trimSpaces

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
        <param-name>fork</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>xpoweredBy</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>trimSpaces</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
</servlet>
					

Configure Apache Tomcat from Eclipse

You can perform this configuration also from Server Eclipse Project

web.xml and server.xml are located in: Servers -> Apache Tomcat 6 -config

JDBC driver installation

The suggested driver is JDBC 3 for PostgreSQL 8.3, and you have to put it under the lib directory of your Tomcat installation.

Example 3.4. Tomcat: lib directory under Linux

/opt/tomcat6/lib


Example 3.5. Tomcat: lib directory under Windows

C:\tomcat6\lib


Chapter 4. How to Instantiate a New Portal from jAPS 2.0 entando

How to Instantiate a New Portal from jAPS 2.0 entando

Introduction

Now we can proceed creating in Eclipse the project for the new Portal.

Some of the required steps are automagically performed, thanks to the build files for Ant. The previously installed Eclipse environment comes with all the necessary to run an Ant build. You can run Ant using the Eclipse GUI and the instructions in this document, even if it is the very first time for you with Ant and Eclipse.

Later on this chapter, you will find detailed instructions to create the new Project. It will be a Dynamic Web Project. We will discuss later about the Dynamic Web Projects, and give some tips and best practices. At the moment, the goal is to create a development environment also including a local execution environment, to be able to immediately check the progresses during the development.

Download jAPS 2.0 entando

First of all, we need the package jAPS2.0_entando-2.2.0-src-0.1.zip from SourceForge. Note the the packeages are inside the folder jAPS 2.0 entando src and jAPS2.0_entando-2.2.0-src . Choose the version that fits your needs; you may want the tar.gz package on GNU Linux environment.

Once donwloaded, choose a temporary location and extract the package.

Import the project in Eclipse

Launch Eclipse and take the following steps in order to import jAPS 2.0 entando in the workspace:

  1. File, then Import...

  2. Choose General, then Existing Projects into Workspace, and press the Next button

  3. Browse and select the directory from which import the project. Obviously, the right directory is the temporary one where you previously extracted the jAPS2.0_entando-2.2.0-src package downloaded from SourceForge

  4. Check the Copy projects into workspace box

  5. Press Finish

When Eclipse finishes to import, in the Project Explore view of Eclipse will be a new project called jAPS2. This project contains all the necessary to instantiate a new Portal project, as we are going to explain. Later you can delete it, if you want.

Create the new project

From the Project Explorer, browse the project jAPS2 and open admin/build_newPortal.xml. This file contains the instructions which Ant can use to create the new project. First of all, it is necessary to customize the name of the source project and the name of the project to create. Find the following two rows:

					<property name="newportal.name" value="myPortalName" />
<property name="newportal.source.name" value="jAPS2" />
				

Now insert the desired project name in place of myPortalName, and optionally the name of the source project which defaults to jAPS2. Save the file.

Example 4.1. build_newPortal.xml: a correct setting

					<property name="newportal.name" value="myportal" />
<property name="newportal.source.name" value="jAPS2" />
					
				

From this point on, we will assume that your new project is called myportal. Now extract the new project from jAPS 2.0 entando:

  1. Open the Ant view: Window, Show View, Ant, Ant

  2. Drag the file build_newPortal.xml and drop it in the Ant view

  3. Expand the node jAPS2 - Extract New Portal

  4. Launch (i.e. with a double-click) the task Create New Portal

Ant will extract the new project from the source project, and will place it in your workspace directory. Now you have to import it into Eclipse, just as you previously did with jAPS2.0_entando-2.2.0-src:

  1. File, then Import...

  2. Choose General, then Existing Projects into Workspace, and press the Next button

  3. Browse and select the directory from which import the project myportal.

  4. Check the Copy projects into workspace box

  5. Press Finish

When Eclipse finishes to import, in the Project Explore view of Eclipse there will be a new project called myportal. In order to avoid any mistake or misunderstanding, now you should better close or delete the jAPS2 project.

Configure the new project

Now it's time for some configurations.

File: buildProperties.xml

Open the file buildProperties.xml, located in the root directory of the project. First of all properly comment or uncomment the blocks of properties suited for Microsoft Windows or Linux, following the XML syntax for comments:

					
<!-- This sentence is commented out  -->
					
				

I.e. if you are using Windows, you have to comment out the Linux block and uncomment the Windows one. And so on...

Then edit the following properties accordingly with your system settings:

Name of the web application, the same as the name of the project
<property name="webappname" value="myportal" />
Username for the Database
<property name="postgres.username" value="agile" />
Password for the Database
<property name="postgres.password" value="agile" />
Path of the PostgreSQL executables

Windows: <property name="postgres.bin.path" location="C:\Programmi\PostgreSQL\8.3\bin" />

Linux: <property name="postgres.bin.path" location="/usr/bin" />

File: context.xml

Now edit some properties for the execution phase. Open the file /jAPS2/WebContent/META-INF/context.xml.

Edit the paths, URLs, and values.

Example 4.2. context.xml on Linux

					<?xml version='1.0' encoding='utf-8'?>
<Context path="/myportal" docBase="./myportal" debug="1" reloadable="true">
	
	<Environment name="logName" value="japs" type="java.lang.String" override="false" />
	<Environment name="logFilePrefix" value="/home/wiz/workspace/myportal/build/temp/japs_log" type="java.lang.String" override="false" />
	<Environment name="logLevel" value="ALL" type="java.lang.String" override="false" />
	<Environment name="logFileSize" value="200000" type="java.lang.String" override="false" />
	<Environment name="logFilesCount" value="10" type="java.lang.String" override="false" />
	
	<Environment name="configVersion" value="production" type="java.lang.String" override="false" />
	
	<Environment name="applicationBaseURL" value="http://localhost:8080/myportal/" type="java.lang.String" override="false" />
	<Environment name="resourceRootURL" value="/myportal/resources/" type="java.lang.String" override="false" />
	<Environment name="protectedResourceRootURL" value="/myportal/protected/" type="java.lang.String" override="false" />
	
	<Environment name="resourceDiskRootFolder" value="/home/wiz/workspace/myportal/WebContent/resources/" type="java.lang.String" override="false" />
	<Environment name="protectedResourceDiskRootFolder" value="/home/wiz/workspace/myportal/WebContent/protected/" type="java.lang.String" override="false" />
	
	<Environment name="indexDiskRootFolder" value="/home/wiz/workspace/myportal/build/temp/indexdir" type="java.lang.String" override="false" />
	
	<Environment name="cacheDiskRootFolder" value="/home/wiz/workspace/myportal/build/temp/cache" type="java.lang.String" override="false" />
	
	<Resource name="jdbc/portDataSource" auth="Container"
		type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" 
		maxActive="8" maxIdle="4" 
		username="agile" password="agile" 
		url="jdbc:postgresql://localhost:5432/myportalPort" />
	
	<Resource name="jdbc/servDataSource" auth="Container" 
		type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" 
		maxActive="8" maxIdle="4" 
		username="agile" password="agile" 
		url="jdbc:postgresql://localhost:5432/myportalServ" />
	
</Context>
					

Create and populate the two databases

jAPS 2.0 entando needs two databases, whose names are prefixed by the name of the project and suffixed respectively by Port and Serv.

Example 4.3. Database names for the project myportal

myportalPort and myportalServ


Ant can automagically create and populate the two databases for you:

Warning

The next procedure drops the two databases if already present.

Please consider doing a backup before proceeding further.

  1. Drag the file build.xml and drop it in the Ant view.

  2. Expand the main node and launch (i.e. with a double-click) the Pg db full update task

Configure the servlet container

Having created a dynamic web project the next step is to configure the servlet container that is going to host the web application during the development stage.

  1. Choose File, New, Other, Server to launch the wizard

  2. Select Apache - Tomcat v6.0 server, then press the Next button

  3. In the window Tomcat Server set the Tomcat installation directory (i.e. the directory where you installed Apache Tomcat in [Chapter 3. Software Requirements]), the press the Next button again

  4. Add myportal to the list of projects configured on this server, then press the Finish button

If everything works fine, Eclipse compiles and deploys the web application in a directory of its own (which we are not interested in knowing at the moment). From now on, you can launch the web application with right mouse button on the project then choosing Run As..., Run on Server.

If a server selection window appears, select the server you just created. You can also get rid of this window checking the Always use this server when running this project setting.

If everything is ok, you can see the homepage of your brand new portal pointing your preferred browser to http://localhost:8080/myportal/.

About Dynamic Web Projects

As hinted before, the project you have just created is a Dynamic Web Project. Eclipse allows you to incrementally deploy (and almost in real time) the application as you progress during the development. That is, in order to see the results of the editing of Java class, or of a JSP page or of a CSS you don't have to copy the modified objects into the execution environment (i.e. the webapps directory of the Apache Tomcat installation path) nor to perform a restart of the server: Eclipse does it all in your place, and very well.

Dynamic Web Projects and jAPS 2.0 entando

Another (hopefully) useful digression. Given a certain dimension of the project, a Portal is built by a team of developers each providing various skills, from Java to the information architecture. Usually, the work group shares the Portal components using a project repository (i.e. CVS or SVN). This requires order and organization. Each developer works in a local area (the Eclipse workspace) which is a replica, periodically synchronized, of the shared repository. In order to be able to share all the components of the project, it is required that they are located in the same working area.

From this, derive some other tips.

Backup the databases

The database records cannot be hosted directly in the workspace: instead, from time to time you can perform an export (i.e. backup) using the Pg db backup Ant task. You brand new project has the proper directory, db/tar under which Ant will store the backup. Just be sure to perform a refresh (i.e. F5 or right mouse button, then Refresh) on the directory or on the whole project to make Eclipse aware of the modifications made by Ant.

Then commit on the project repository.

Best practice about resources saving

As you should know, jAPS 2.0 entando comes with a powerful and fully integrated CMS. To build a Portal using jAPS 2.0 entando also means to begin to populate it with some images and attachments (which in jAPS 2.0 entando are called Resources). Being files, you can host them in the project area (see the configuration of the parameter resourceDiskRootFolder). In order to be able to view this resources under Tomcat, it is required for them to be located in deploy area of the application. And here it comes the Dynamic Web Project again: if you save the resource in a proper directory under the project area, Eclipse will automagically deploy them in the execution area for Tomcat. Everything goes really fine, with a warning: from time to time you must perform a refresh both of the project in Eclipse, to make it aware of the new or modified resources, and of the page in the browser to make it aware of the incremental deploy done by Tomcat and guided by Eclipse.

Example 4.4. resourceDiskRootFolder: a useful setting

resourceDiskRootFolder=/home/wiz/workspace/myportal/WebContent/resources/


The big picture is the following:

  • The components of the project (that is, the web application) are in workspace/myportal
  • Eclipse deploys them in a directory, say DeployArea
  • Apache Tomcat runs the web application placed in the directory DeployArea
  • When the developer updates an object in workspace/myportal, Eclipse copies it in DeployArea and if it is necessary also restarts Tomcat
  • Usually the developer keeps opened at the same time both Eclipse and the browser, on different windows, to verify in real time the effects of his job. In Eclipse he works on the components in workspace/myportal, using the browser he can use the web application Tomcat is executing in the DeployArea.

Let's see what happens when you upload a new Image resource using the CMS of jAPS 2.0 entando:

  • When you upload a new image, the web application stores it under the path specified in the configuration, which is a directory in workspace/myportal
  • With a refresh on the project window, Eclipse becomes aware of the new image file
  • Eclipse then copies the image in the DeployArea
  • If the page currently loaded in the browser contains a reference to the image, to make it show up it is necessary to perform a refresh in the browser window (i.e. reloading the page).

As you can imagine all these tips regard exclusively the development environment and not the final production environments, where only the execution area does exist.

Clean & Refresh before a commit

If you use a shared project repository please remember to perform a clean (there is the proper Ant task) and a refresh in Eclipse before every single commit, in order to allow Eclipse to correctly find and synchronize all the objects coming from the CMS, from the database, and from any other external software.

Compile soon after a clean

This is simple: after every clean performed by Ant as explained in the previous tip, and prior to start the integrated local execution environment again, compile the sources again using the compile Ant task. Otherwise the execution will fail, because you just cleaned away every compiled class!

Apache Tomcat Configuration

Remember you can always customize Apache Tomcat just editing configuration files located in Apache - Tomcat 6-config directory from project Server

See "Configuring Apache Tomcat" section for further details.