« Torna a Development

Fast Plugin Development

Save time by allowing developers to work with exploded plugin WARs instead of having to package them for deployment.

Create a context file #

The first thing to do is create a context file for the plugin, pointing to the exploded WAR: Create an xml file called like your plugin. For example, if your plugin is a portlet called something-portlet your file must be called something-portlet.xml and the content will be the following:

   <Context
   path="foo"
   docBase="D:/Projects/liferay-plugins-sdk/portlets/foo-portlet/docroot"
   />

Deploy context file #

Once created just drop this file into the Liferay autodeploy directory. Liferay will copy this file to TOMCAT_DIR/conf/Catalina/localhost and the plugins will be registered. If the WAR was previously deployed, a new copy of the context file to the autodeploy directory will cause a redeploy of the exploded WAR. (If you had deployed your plugin before, it is advised to remove the old deployed application in webapps folder and restart Tomcat).

Copy dependencies #

You may probably need some libraries and tlds that were previously copied from the core. In order to know which ones you need, go to the webapps/somthing-portlet/WEB-INF folder and copy the lib and tld folders to your plugin WEB-INF folder too.

Using Fast Development in Tomcat #

From now on, if you change jsp files, they are modified when you refresh the page in your browser. For java classes and xml files you need to do ant compile from the plugin folder and copy again the context file into the Liferay autodeploy directory unless the Tomcat's context property "reloadable" is set to true. To do so, open the $TOMCAT_LIFERAY/conf/context.xml file and replace the line <Context> by <Context reloadable="true">. Then restart Tomcat. You can now update any part of the webapp (JSP, JSF pages... Java beans, servlets.... and they will automatically be reloaded by the Tomcat class loader).

Automating the configuration for fast development #

The steps outlined in the previous sections are valid for one portlet. If you are working with many portlets you may want to automate it so that the configuration is easily applied to any new portlet.

The following subsections explain how to achieve this by customizing the build scripts of the Plugins SDK

1) Extend the 'create' target #

Add the following quoted with EXPLODEDWARTEMPLATE inside the create target in the pluginsSDK\portlets\build.xml file:

	<replace dir="${portlet.name}-portlet">
		<replacefilter token="@portlet.name@" value="${portlet.name}" />
		<replacefilter token="@portlet.display.name@" value="${portlet.display.name}" />
	</replace>					
	
	<!--<EXPLODEDWARTEMPLATE>-->
	<sequential>
		<antelope:stringutil string="${basedir}" property="pluginpath">
			<antelope:replace regex="\\" replacement="/" />
		</antelope:stringutil>
		<property name="plugincontextfile" value="${pluginpath}/${portlet.name}-portlet/${portlet.name}-portlet.xml" />
		<copy file="${pluginpath}/EXPLODEDWARTEMPLATE-portlet.xml" tofile="${plugincontextfile}" />
		<replace file="${plugincontextfile}">
			<replacefilter token="@portlet.name@" value="${portlet.name}" />
			<replacefilter token="@pluginpath@" value="${pluginpath}" />
		</replace>					
	</sequential>
	<!--<EXPLODEDWARTEMPLATE>-->
	
	<mkdir dir="${portlet.name}-portlet/docroot/WEB-INF/tld" />

2) Create a template Tomcat configuration file #

Create a file named EXPLODEDWARTEMPLATE-portlet.xml inside the pluginsSDK\portlets directory with the following content:

	<?xml version="1.0"?>
	
	<Context
	path="@portlet.name@"
	docBase="@pluginpath@/@portlet.name@-portlet/docroot"
	/>

3) Done #

Now you can run ant create for creating new portlets as usual and they will be created with 'fast development' preconfigured.

Other useful customizations #

Deployment of exploded WAR using ANT #

Add the following new target inside the pluginsSDK\portlets\build-common-portlet.xml file:

	<target name="deploy-exploded" depends="compile">
		<sequential>
			<antelope:stringutil string="${basedir}/${plugin.name}.xml" property="plugincontextfile">
				<antelope:replace regex="\\" replacement="/" />
			</antelope:stringutil>
			<copy file="${plugincontextfile}" todir="${auto.deploy.dir}" />
		</sequential>
	</target>

Note that you also have to add the antelope prefix:

		xmlns:antelope="antlib:ise.antelope.tasks"

Now, you could do a deploy of the exploded WAR using: ant deploy-exploded

1 Allegato
43636 Visualizzazioni
Media (0 Voti)
La media del punteggio è 0.0 stelle su 5.
Commenti
Commenti Autore Data
Thanks for the tip. However, it does not run... Fabrice Clari 5 dicembre 2008 0.45
I've changed portal property:... Mariusz Nosiński 11 marzo 2009 7.56
It is nice. It did run correctly on my side... Jonas Yuan 24 febbraio 2009 13.58
Yes. This task could be normally handled by... Jonas Yuan 24 febbraio 2009 14.35
I must be doing something wrong, I can't get... Seth Wallace 1 dicembre 2009 1.50
For the docBase parameter, I specified Tomcat's... Mike Harris 1 aprile 2011 13.24

Thanks for the tip.
However, it does not run correctly on my side when copying context file to Liferay hot deploy directory, but it works when copying that file directly to $TOMCAT_LIFERAY/conf/localhost/Catalina.

I have opened a ticket since it is not the normal behaviour: http://issues.liferay.com/browse/LPS-883.

Fabrice.
Inviato il 05/12/08 0.45.
It is nice. It did run correctly on my side when copying context file to Liferay hot deploy directory - at revision 26723.

Thanks

Jonas Yuan
Inviato il 24/02/09 13.58.
Yes. This task could be normally handled by the Liferay hot deploy process: adding Ant target deploy-exploded in Plugins SDK - build-common-plugin.xml.

Add following lines in build-common-plugin.xml

// after <property name="plugin.file" value="${project.dir}/dist/${plugin.name}-${lp.version}.${plugin.version}.war" />

<property name="context.file" value="${project.dir}/portlets/${plugin.name}/${plugin.name}.xml" />

// after <target name="deploy" depends="war">
// <copy file="${plugin.file}" todir="${auto.deploy.dir}" />
// </target>

<target name="deploy-exploded" depends="compile">
<copy file="${context.file}" todir="${auto.deploy.dir}" />
</target>

Done!
Inviato il 24/02/09 14.35 in risposta a Jonas Yuan.
I've changed portal property: 'auto.deploy.tomcat.conf.dir=../conf/Catalina/localhost' to 'auto.deploy.tomcat.conf.dir=${catalina.base}/conf/Catalina/localhost', and portlets deploys correcty when context file is copied to autodeploy dir.
Inviato il 11/03/09 7.56 in risposta a Fabrice Clari.
I must be doing something wrong, I can't get this to work with 5.2.3. Tomcat is correctly picking up my Context.xml file and trying to load the docroot I pointed to, but it's complaining about ClassNotFoundExceptions for com.liferay.portlet.StrutsPortlet.

I copied over the dependencies from the original, normal deployed tomcat\webapps\myPortlet directory as mentioned (TLD and LIB folders). Is the jar containing StrutsPortlet somewhere else?
Inviato il 01/12/09 1.50.
For the docBase parameter, I specified Tomcat's webapp folder of my project and it worked fine.
Inviato il 01/04/11 13.24 in risposta a Seth J Wingert.