Setup Jboss Ent. With Liferay Portal

My Environment

Jboss Boss AS Ent. 4.3.0.G.A

LifeRay Portal 4.4.2

MySql 5.0.45 community

(Linux and Windows almost use the same setting steps)

1. run the Jboss AS installer to install it.

Windows : double click

Linux : terminal>java -jar enterprise-installer-4.3.0.GA-1.ep1.8.jar

2. install MySql from its installer.

3. download 3 files of liferay :

liferay-portal-4.4.2-with-dependencies.war

liferay-portal-dependencies-4.4.2.zip

liferay-portal-sql-4.4.2.zip

4. create an utf-8 database in your mysql, I use lportal as database name here.

mysql>create database lportal character set utf8;

5. unpack liferay-portal-sql-4.4.2.zip, import the database dump under [unpack]/create-minimal/create-minimal-mysql.sql

mysql -uroot lportal < [path from above]/create-minial-mysql.sql –default-character-set=utf8

6. open [JBOSS_HOME]/jboss-as/server/default/deploy/jboss-web.deployer/conf/web.xml

Replace :

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

With :

<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.apache.catalina.servlets.DefaultServlet</servletclass>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>input</param-name>
<param-value>4096</param-value>
</init-param>
<init-param>
<param-name>output</param-name>
<param-value>4096</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

7. create [JBOSS_HOME]/jboss-as/server/default/deploy/liferay-ds.xml

<?xml version="1.0"?>
<datasources>
	<local-tx-datasource>
		<jndi-name>jdbc/LiferayPool</jndi-name>
		<connection-url>jdbc:mysql://hostname:3306/lportal</connection-url>
		<driver-class>com.mysql.jdbc.Driver</driver-class>
		<user-name></user-name>
		<password></password>
		<min-pool-size>5</min-pool-size>
	</local-tx-datasource>
</datasources>

8. Download mysql-connector-java-5.1.5-bin.jar, copy to [JBOSS_HOME]/jboss-as/server/default/lib/

9. Unpack liferay-portal-dependencies-4.4.2.zip to [JBOSS_HOME]/jboss-as/server/default/lib/

resulting structure will be like this :

[JBOSS_HOME]/jboss-as/server/default/lib/liferay-portal-dependencies-4.4.2/portlet.jar

/portal-kernel.jar

/portal-service.jar

10 .Setup mail properties, open [JBOSS_HOME]/jboss-as/server/default/deploy/mail-service.xml

modify : User, Password, pop3.host, smtp.host, mail.from

11. Open [JBOSS_HOME]/jboss-as/server/default/conf/login-config.xml, comment out the entire <application-policy name=”other”>

12. unpack liferay-portal-4.4.2-with-dependencies.war, rename the unpacked folder to liferay-portal.war

Move dom4j.jar, jaxen.jar from liferay-portal.war/WEB-INF/lib to [JBOSS_HOME]/jboss-as/lib

Move commons-collections.jar from liferay-portal.war/WEB-INF/lib to [JBOSS_HOME]/jboss-as/server/default/lib (overwrite it if it is already there)

remove hibernate3.jar, jboss-hibernate.jar from [JBOSS_HOME]/jboss-as/server/default/lib

Move liferay-portal.war to [JBOSS_HOME]/jboss-as/server/default/deploy/

13. open [JBOSS_HOME]/jboss-as/server/default/deploy/jbossjca-service.xml

change <attribute name=”Debug”>true</attribute>

to <attribute name=”Debug”>false</attribute>

14. open [JBOSS_HOME]/jboss-as/server/default/deploy/jboss-messaging.sar/destinations-service.xml

clear all text between <server></server>

15. open [JBOSS_HOME]/jboss-as/bin/run.conf

modify the JAVA_OPTS setting to this one

      JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"

16. But in my experience, JBoss Ent. may not pick up this setting in windows, so

Windows : open [JBOSS_HOME]/jboss-as/bin/run.bat

find : rem JVM memory allocation pool parameters. Modify as appropriate.

change the line follow this one to

set JAVA_OPTS=%JAVA_OPTS% -Xms256m -Xmx512m -XX:MaxNewSize=256m -XX:MaxPermSize=256m

17. start Jboss AS, beware that there are more then one AS : All, default, minimal, production.

The one we setup is default, you can start by

Windows : [JBOSS_HOME]/jboss-as/bin/run.bat -c default

Linux : [JBOSS_HOME]/jboss-as/bin/run.sh -c default

18. open http://localhost:8080, you should see liferay running

19. change the Jboss AS to allow remote connection and bind to port 80

open [JBOSS_HOME]/jboss-as/server/default/deploy/jboss-web.deployer/server.xml

change :

    <Connector port="8080" address="${jboss.bind.address}"
         maxThreads="250" maxHttpHeaderSize="8192"
         emptySessionPath="true" protocol="HTTP/1.1"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true" />

to :

    <Connector port="80" address="0.0.0.0"
         maxThreads="250" maxHttpHeaderSize="8192"
         emptySessionPath="true" protocol="HTTP/1.1"
         enableLookups="false" redirectPort="8443" acceptCount="100"
         connectionTimeout="20000" disableUploadTimeout="true" />

Then reboot JBoss AS.

MySql 5 basic handling of utf-8 database

1. Setup default mysql character set
modify mysql.cnf
[client]
default_character_set=utf8
[mysqld]
default-character-set=utf8
character-set-server = utf8
collation-server = utf8_general_ci
[mysql]
default_character_set=utf8

You will need to setup apache too if your website need utf-8
modify \apache\conf\extra\httpd-languages.conf
find :
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
add :
AddLanguage UTF-8 .utf8
find :
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
change :
LanguagePriority UTF-8 en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW
add :
DefaultLanguage UTF-8
AddDefaultCharSet UTF-8

2. Check database character set
mysql>SHOW VARIABLES LIKE ‘character_set%’;
mysql>SHOW VARIABLES LIKE ‘collation%’;
Change database character set
mysql>SET NAMES utf8;
mysql>SET CHARACTER SET utf8;
mysql>SET GLOBAL/SESSION character_set_XXX=utf8

3. Create utf-8 database
mysql>create database db_name character set utf8;

4. Restore utf-8 dump
mysql -uroot dbname < dump.sql –default-character-set=utf8

Remark: please note that mysql start supporting utf-8 from 5.0

Develop JSF1.2 with Netbeans 5.5.1 running on Tomcat 6 with Mysql backend

My Environment

JSF 1.2

Netbeans 5.5.1

Tomcat 6

Mysql 5

Prepare Tomcat 6

Download and unpack Tomcat 6.

Run: [tomcat6]\bin\startup.bat in windows

Shutdowm: [tomcat6]\bin\shutdown.bat in windows

Change port: [tomcat6]\apache-tomcat-6.0.16\conf\server.xml

Add user: [tomcat6]\apache-tomcat-6.0.16\conf\tomcat-user.xml

<role rolename="manager"/> <user username="tomcat" password="s3cret" roles="manager"/>

Open server manager in Netbeans-> Add Server, choose Tomcat 5.5(I don’t see Tomcat 6 and don’t know how to add it). Catalina Home means where you unpack Tomcat 6. username/password is the manager username/password we set previously.

You can run and deploy project using Tomcat 6 by now.

Prepare Mysql

Download and run it as a service from Mysq which will be trivial to teach.

Copy JDB-connecter for Mysql under [tomcat6]\lib

Add the following setting in your context

<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"
removeAbandoned="true" emoveAbandonedTimeout="60"/>
</Context>

Context for tomcat 6 can be in the following ways!

  • in the $CATALINA_HOME/conf/context.xml file: the Context element information will be loaded by all webapps
  • in the $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host
  • in individual files (with a “.xml” extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml. The default web application may be defined by using a file called ROOT.xml.
  • if the previous file was not found for this application, in an individual file at /META-INF/context.xml inside the application files
  • inside a Host element in the main conf/server.xml

I prefer the /META-INF/context.xml in your project under <web-app>

Put this in your web.xml in your project:

<description>MySQL Test App</description>
 <resource-ref> 
<description>DB Connection</description> 
<res-ref-name>jdbc/TestDB</res-ref-name>       
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth>   
</resource-ref>

***注意:如果你在Netbeans5.5裡面run你的project會有問題,因為netbeans5.5自動include mysql connector,會跟[tomcat 6]\lib裡面的相沖

You are now ready to use Myql in your project.

Prepare JSF

JSF1.2 need Servlet 2.5 and JSP 2.1 which tomcat 6 can provide.

Download JSF and JSTL

Create Web project and Add JSF framework in project properties.

This is the same as doing JSF setting in web.xml, netbeans user don’t need to do this by hand.

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>

<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

Add JSF managed bean by right clicking in project navigator.

Which will automatically add setting in faces-config.xml by Netbeans,

you can do it yourself by adding the following in faces-config.xml:

<managed-bean>
<managed-bean-name>ManagedBean</managed-bean-name>
<managed-bean-class>maxi.fun.ManagedBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

Replace library with those we download previously : jsf-api.jar and jsf-impl.jar for JSF ;standard.jar and jstl.jar for JSTL

JSF file can be .jsf or .jsp, I don’t know how to create .jsf. so I just use .jsp instead.

You are all set. Have Fun