Nice tutorial by http://www.eusia.info
Have a look !!!
Assuming that you have JDK and Maven set up in you machine, I will write here how we can have a liferay project in minimal effort and make it distributable in all environments.
Have a look !!!
Assuming that you have JDK and Maven set up in you machine, I will write here how we can have a liferay project in minimal effort and make it distributable in all environments.
We will use Maven archtype plug-in to create liferay project.
Consider a folder as your project home, like: /home/manna/examples/liferay
if
you working with maven you can have several maven settings based on
project requirements, so better to have a different maven settings file
like here we have : /home/manna/.m2/eusiaweb.xml
<settings>
<profiles>
<profile>
<id>examples</id>
<repositories>
<repository>
<id>sonatype</id>
<url>http://oss.sonatype.org</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven</id>
<url>http://repo2.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>examples</activeProfile>
</activeProfiles>
</settings>
when this command
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 217:
appears write word “pom” then select “1” then select latest “3”
after
that you will find a folder under you project home named
“liferayexample1” , lets change the directory and get into this folder.
And repeat this process of creating pom and create 5 more folders
- dist
- hooks
- ext
- portlets
- themes
in
parent pom.xml you will get these five modules added. But we do not
need dist as a module as it will work as an external project to prepare
the project infrastructure.
So we will remove it and also add some dependencies in the parent pom and liferay maven plugin also. And we will add some properties which will help in our build process.
So we will remove it and also add some dependencies in the parent pom and liferay maven plugin also. And we will add some properties which will help in our build process.
So parent-pom will look like below:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.eusia.examples</groupId>
<artifactId>liferayexample1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>liferayexample1</name>
<properties>
<project.home>/home/manna/examples/liferay</project.home>
<project.src.dir>${project.home}/src</project.src.dir>
<project.build.dir>${project.home}/build</project.build.dir>
<project.bundle.dir>${project.build.dir}/bundle</project.bundle.dir>
<app.server.name>apache-tomcat-6.0.35</app.server.name>
<app.server.dir>${project.bundle.dir}/${app.server.name}</app.server.dir>
<liferay.deploy.dir>${project.bundle.dir}/deploy</liferay.deploy.dir>
<liferay.auto.deploy.dir>${project.bundle.dir}/deploy</liferay.auto.deploy.dir>
<liferay.maven.plugin.version>6.1.0</liferay.maven.plugin.version>
<liferay.version>6.1.0</liferay.version>
<autoDeployDir>${liferay.deploy.dir}</autoDeployDir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!-- ================================================ Liferay =============================================== -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-client</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-impl</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-kernel</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-web</artifactId>
<version>${liferay.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-bridges</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-taglib</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>com.liferay.maven.plugins</groupId>
<artifactId>liferay-maven-plugin</artifactId>
<version>${liferay.maven.plugin.version}</version>
<configuration>
<liferayVersion>${liferay.version}</liferayVersion>
<deployDir>${liferay.deploy.dir}</deployDir>
<autoDeployDir>${liferay.deploy.dir}</autoDeployDir>
<unpackWar>true</unpackWar>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>ext</module>
<module>hooks</module>
<module>portlets</module>
<module>themes</module>
</modules>
</project>
in file system it would look like:
now
lets start working on creating a distributable for development
environment, it can be optimized and you as a expert can generate or
prepare it far more better and anywhere you like, below I will just try
to give a idea how it can be managed:
lets think we want create a bundle of tomcat, so here the folder structure I preferred is:
- build
- liferay-tomcat-bundle (example contains only this)
- apache-tomcat-version
- deploy
- data
- liferay-jboss-bundle
so lets modify the dist:
in dist we will add folder:
- src/main/resources/tomcat-support
why
this folder, this folder is contain all required configuration for
apache-tomcat and jars to support liferay. In catalina.properties file
ad ext folder as common-loader folder.
Now we will modify the pom.xml of dist to
- create the folder structures
- download apache-tomcat
- unpack tomcat
- get Liferay war>
- unpack war
- and prepare tomcat for liferay start
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>liferayexample1</artifactId>
<groupId>com.eusia.examples</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.eusia.examples.liferayexample1</groupId>
<artifactId>dist</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>dist</name>
<properties>
<app.server.name>apache-tomcat-6.0.35</app.server.name>
<app.server.dir>${project.bundle.dir}/${app.server.name}</app.server.dir>
<liferay.deploy.dir>${project.bundle.dir}/deploy</liferay.deploy.dir>
<liferay.auto.deploy.dir>${project.bundle.dir}/${app.server.name}/webapps</liferay.auto.deploy.dir>
<liferay.maven.plugin.version>6.1.0</liferay.maven.plugin.version>
</properties>
<profiles>
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<project.build.dir>${project.home}/build</project.build.dir>
<project.bundle.dir>${project.build.dir}/liferay-tomcat-bundle</project.bundle.dir>
</properties>
<dependencies>
<!--
================================================ Liferay
=============================================== -->
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-client</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-impl</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-web</artifactId>
<version>${liferay.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-bridges</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-java</artifactId>
<version>${liferay.version}</version>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>util-taglib</artifactId>
<version>${liferay.version}</version>
</dependency>
<!-- Project -->
<dependency>
<groupId>com.eusia.web.ext</groupId>
<artifactId>eusiaweb-ext</artifactId>
<version>${project.version}</version>
<type>war</type>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<configuration>
<filesets>
<fileset>
<directory>${project.build.dir}</directory>
<includes>
<include>**/*</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>default-cli</id>
<phase>generate-resources</phase>
<configuration>
<tasks>
<mkdir dir="${project.bundle.dir}" />
<mkdir dir="${project.bundle.dir}/data" />
<mkdir dir="${project.bundle.dir}/deploy" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>default-cli-unzip</id>
<phase>prepare-package</phase>
<configuration>
<tasks>
<unzip src="${project.bundle.dir}/temp/apache-tomcat-6.0.35.zip"
dest="${project.bundle.dir}" />
<delete dir="${app.server.dir}/webapps/ROOT"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>wagon-maven-plugin</artifactId>
<version>1.0-beta-4</version>
<configuration>
<serverId>apache.org</serverId>
<url>http://www.apache.org/dist/tomcat/tomcat-6/v6.0.35/bin/</url>
<fromFile>apache-tomcat-6.0.35.zip</fromFile>
<toDir>${project.bundle.dir}/temp/</toDir>
</configuration>
<executions>
<execution>
<id>http-download-single</id>
<phase>generate-resources</phase>
<goals>
<goal>download-single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>unpack</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-web</artifactId>
<version>${liferay.version}</version>
<type>war</type>
<overWrite>true</overWrite>
<outputDirectory>${liferay.auto.deploy.dir}/ROOT</outputDirectory>
<excludes>**/*.war</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.liferay.portal</groupId>
<artifactId>portal-service</artifactId>
<version>${liferay.version}</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>${app.server.dir}/lib</outputDirectory>
<excludes>**/*.war</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-tomcat-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${app.server.dir}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources/tomcat-support</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And now change directory to dist and run: install
and after successful build with liferay in tomcat it will look like this:
then to start tomcat we have to give executable permissions to *.sh like:
chmod u+x bin/*.sh
and start tomcat :
./catalina.sh start