Liferay Portal Development with Eclipse
Prerequisite
Following software required to develop liferay portals
1. make sure JDK 6 or above installed in your machine
2. get the Eclipse kepler version from https://www.eclipse.org/downloads/index-developer.php?release=kepler
3. following liferay archives download from below link
i) bundle with tomcat v6.2
ii) plugin SDK v6.2
NOTE : liferay plugin SDK has it own way of development environment which uses ANT as build tool. hence i would recommend not to use maven for liferay development.
Development Environment Setup
1.Launch eclipse and create eclipse workspace
2.Install liferay plugin for eclipse using http://releases.liferay.com/tools/ide/latest/milestone/
3.Extract liferay bundle and plugin SDK archives into same directory make sure folder shouldn’t have any spaces
C:/liferay/liferay-portal-6.2-ce-ga2
C:/liferay/liferay-plugins-sdk-6.2
4. configure liferay tomcat server and plugin sdk as shown in the below link
NOTE : each service.xml should have unique name space otherwise you will get run time error
as Build namespace NH has build number XX which is newer than XX
Connecting To SQL Server/MySQL Database
liferay default uses HSQL as database to store portal information. that can be chaged using below portal-ext.properties file.create and place this file under
C:/liferay\liferay-portal-6.2-ce-ga2\tomcat-7.0.42\webapps\ROOT\WEB-INF\classes
# MySQL
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=XXXXXX
#SQL Server
#jdbc.default.driverClassName=net.sourceforge.jtds.jdbc.Driver
#jdbc.default.url=jdbc:jtds:sqlserver://192.168.204.153/tvajjala_liferay
#jdbc.default.username=sa
#jdbc.default.password=XXXXXX
if you want connect to other than above two database required settings can be found at
Steps to create Portlet
1. go to portlets folder under plugin SDK and run the command as shown below
Import this project into eclipse as liferay plugin SDK project
OR
you can create from eclipse directly as new Liferay PlugIn Project which will creates in the same location.
Adding Spring features into portlet
if you configures plugin SDK and bundle server in the eclipse (Liferay IDE). you can easily enable spring features into your portlet.
under WEB-INF there is one file with name liferay-plugin-package.properties.
open file in eclipse and you can find portal dependent jars area. click on add button as shown below and select required JARS . if you want to add new thirdparty JARS just copy first those jars into bundle tomcat /ROOT/WEB-INF/lib folder and those jars can be available here
similarly you can add taglibs as per your need. this makes your final build size very less to deploy.add the spring configuration files manually and configure as per the need.
Service Builder
to create portlet specific database you need to use service builder feature.
from eclipse select portlet and → new → service builder. it will create sample service.xml
modify service.xml file as per your need and run the command
ant build-service command
Adding finder method in service builder
write finder method as per the need as shown below which are similar to select queries in SQL
<finder name="MR" return-type="Object">
<finder-column name="mrNumber" />
</finder>
run the service builder command as ant build-service which will generates required methods in
NapierUserUtil class but those not supposed to access directly. they are not run under transaction.
hence we need to write custom methods in NapierUserLocalServiceImpl class as shown below
public X getUserByMRNumber(String mrNumber)
throws NoSuchXException, SystemException {
return XUtil.findByMR(mrNumber);
}
once the required methods are written run the service builder, these signatures available in the
NapierUserLocalServiceUtil through which we have to access the methods in the controller.
XnapierUser = XLocalServiceUtil.getUserByMRNumber(mrnumber);
when you deploy portlets it will automatically creates required tables into database.
NOTE: whenever you change package name /entity names in the service builder please delete following highlighted directories (classes,lib,service,sql) to avoid conflicts in the code. and run the service builder to generate fresh one.
Comments
Post a Comment