Customize Liferay SDK plugins(portlet) to Maven project

In our case, we use maven portlet instead of default ant portlet, every time we need to modify. What I do is to create our own template and read properties file to create the project.

Here is my example:

build.xml

<?xml version="1.0"?>
<!DOCTYPE project>


<project name="portlets" basedir="." default="deploy" xmlns:antelope="antlib:ise.antelope.tasks">
	<property name="project.dir" value=".." />


	<import file="../build-common-plugins.xml" />


	<target name="create">
		<if>
			
			<not>
				<isset property="properties.file.name" />
			</not>
			<then>
				<echo message="This task must be called by create.bat." />
			</then>
			<else>
				<if>
					<not>
						<available file="${properties.file.name}"/>
					</not>
					<then>
						<fail>${properties.file.name} doesn't exist.</fail>
					</then>
				</if>


				<property file="${properties.file.name}"/>
				
				<if>
					<or>
						<equals arg1="${portlet.name}" arg2="" />
						<equals arg1="${portlet.display.name}" arg2="" />
					</or>
					<then>
						<fail>portlet.name or portlet.display.name isn't set</fail>
					</then>
				</if>
				
				<if>
					<not>
						<isset property="portlet.parent.dir" />
					</not>
					<then>
						<property name="portlet.parent.dir" value="${basedir}" />
					</then>
				</if>
				
				<property name="portlet.dir" value="${portlet.parent.dir}/${portlet.name}-portlet" />


				<if>
					<available file="${portlet.dir}" />
					<then>
						<fail>${portlet.dir} already exists.</fail>
					</then>
				</if>
				<!-- my_portlet_tmpl is a spring maven tmpl -->
				<copy todir="${portlet.dir}">
					<fileset dir="${project.dir}/tools/my_portlet_tmpl" />
				</copy>
				
				<antelope:stringutil string="${portlet.display.name}" property="portlet.java.class.name">
					<antelope:replace regex="\s+" replacement="" />
					<antelope:trim />
				</antelope:stringutil>


				<antelope:stringutil string="${portlet.name}" property="portlet.java.package.name">
					<antelope:replace regex="-" replacement="" />
					<antelope:trim />
				</antelope:stringutil>
				<replace dir="${portlet.dir}">
					<replacefilter token="@portlet.name@" value="${portlet.name}" />
					<replacefilter token="@portlet.display.name@" value="${portlet.display.name}" />
					<replacefilter token="@portlet.java.class.name@" value="${portlet.java.class.name}" />
					<replacefilter token="@portlet.java.package.name@" value="${portlet.java.package.name}" />
				</replace>
				
				<mkdir dir="${portlet.dir}/src/main/webapp/WEB-INF/tld" />


				<copy todir="${portlet.dir}/src/main/webapp/WEB-INF/tld">
					<fileset dir="${app.server.portal.dir}/WEB-INF/tld">
						<include name="aui.tld" />
						<include name="liferay-faces.tld" />
						<include name="liferay-portlet.tld" />
						<include name="liferay-portlet-ext.tld" />
						<include name="liferay-security.tld" />
						<include name="liferay-theme.tld" />
						<include name="liferay-ui.tld" />
						<include name="liferay-util.tld" />
					</fileset>
				</copy>
			</else>
		</if>
	</target>
</project>

create.bat

@echo off

if "" == "%1" goto errorCreate

call ant -Dproperties.file.name=%1 create

rem call ant deploy

goto end

:errorCreate
	echo.
	echo Usage: create.bat build.properties
	echo e.g. build.properties
	echo portlet.name=First
	echo portlet.display.name=First Portlet
	echo.
	echo The first hello-world is your portlet id. A new directory will be created based
	echo on the portlet id.
	echo.

:end



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Title: Mastering Apache Maven 3 Author: Prabath Siriwardena Length: 298 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2014-12-29 ISBN-10: 1783983868 ISBN-13: 9781783983865 Maven is the number one build tool used by developers for more than a decade. Maven stands out among other build tools due to its extremely extensible architecture, which is built on top of the concept "convention over configuration". This has made Maven the de-facto tool used to manage and build Java projects. This book is a technical guide to the difficult and complex concepts in Maven and build automation. It starts with the core Maven concepts and its architecture, and then explains how to build extensions such as plugins, archetypes, and lifecycles in depth. This book is a step-by-step guide that shows you how to use Apache Maven in an optimal way to address your enterprise build requirements. What you'll learn Apply Maven best practices in designing a build system to improve developer productivity Customize the build process to suit your enterprise needs by developing custom Maven plugins, lifecycles, and archetypes Implement and deploy a Maven repository manager to manage the build process in a better and smoother way Design the build in a way that prevents any maintenance nightmares with proper dependency management Optimize Maven configuration settings Create your own distribution archive using Maven assemblies Build custom Maven lifecycles and lifecycle extensions Table of Contents Chapter 1: Apache Maven Quick Start Chapter 2: Demystifying Project Object Model Chapter 3: Maven Configuration Chapter 4: Build Lifecycles Chapter 5: Maven Plugins Chapter 6: Maven Assemblies Chapter 7: Maven Archetypes Chapter 8: Maven Repository Management Chapter 9: Best Practices

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值