Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why
« Back to Development

Develop Liferay Core with Tomcat

Save time by allowing developers to deploy with directories instead of always copying files on Tomcat. Orion and Oracle 10 has great ways for this and has traditionally been used by Liferay developers to save time. Now we've ported the same concept to Tomcat.

Setup #

A few steps are needed. In the following steps it is assumed that you have checked out the sources of Liferay Portal to:

 D:/Projects/liferay/portal/trunk

Change that to whatever directory you are using either on Windows or Linux.

1) Modify tomcat/conf/web.xml #

By default, Tomcat checks modified JSPs every 4 seconds, let's truncate that to 0 seconds. Add these two init-params to the JspServlet.

    <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
        <init-param>
            <param-name>modificationTestInterval</param-name>
            <param-value>0</param-value>
        </init-param>
        <init-param>
            <param-name>development</param-name>
            <param-value>true</param-value>
        </init-param>

2) Setup context file load order #

Tomcat does not have a guaranteed load order for web apps. We wrote a custom HostConfig to ensure that context files are always loaded alphabetically (case sensitive).

Modify tomcat/conf/server.xml, add the custom hostConfigClass

      <Host name="localhost" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false"
       hostConfigClass="com.liferay.support.tomcat.startup.PortalHostConfig">

3) Run "ant clean" #

To make sure that your current Tomcat doesn't contain the portal deployed.

4) Modify tomcat/conf/Catalina/localhost/ROOT.xml #

   <Context
   path=""
   crossContext="true"
   docBase="D:/Projects/liferay/portal/trunk/portal-web/docroot"
   >
   ...

5) Modify your app.server.${username}.properties #

Set

    app.server.tomcat.portal.dir=D:/Projects/liferay/portal/trunk/portal-web/docroot

The property "app.server.tomcat.dir" must remain pointing to your Tomcat folder, as usual.

6) Run "ant all" from the source #

Be sure to stop the tomcat instance and then run:

    ant all

Note: it has been reported that if this command is executed while tomcat is running the file ROOT.xml is mistakenly deleted by Tomcat and has to be recovered manually.

7) Cleaning #

Delete unnecessary webapps in tomcat/webapps/cms-web , laszlo-web, tunnel-web, etc (unless you're doing work on laszlo related portlets, tunneling, etc).

8) Fixing Paths #

If you are using Plugins SDK remember to change the build.username.properties :

app.server.lib.portal.dir= .../portal-web/docroot/WEB-INF/lib
app.server.portal.dir= .../portal-web/docroot

Usage #

From now on, modifying and testing the changes in Liferay's source code is a lot faster. Following are a description of the steps necessary for some common changes:

Change a JSP or velocity file #

  1. Make the change
  2. Hit refresh in the browser

Change a class in portal-impl, portal-kernel or portal-service #

  1. Make the change
  2. Stop tomcat
  3. Execute from portal-impl 'ant compile-fast'
  4. Start tomcat
  5. Hit refresh in the browser

Change a WEB-INF/*.xml file #

  1. Make the change
  2. Stop tomcat
  3. Execute 'ant build-website'
  4. Start tomcat
  5. Hit refresh in the browser

Changes in other modules #

  1. Stop tomcat
  2. Run ant deploy from within each of the modified modules
  3. Start tomcat

Other changes #

If you've made changes elsewhere or you've made changes to a lot of places:

  1. Stop tomcat
  2. Run ant deploy from the root directory
  3. Start tomcat

Final notes #

Be aware that with these settings your classes are now built to D:/Projects/liferay/portal/trunk/portal-web/docroot/WEB-INF/classes instead of portal-impl/classes.

0 Attachments
42660 Views
Average (3 Votes)
The average rating is 1.33333333333333 stars out of 5.
Comments
Threaded Replies Author Date
What is the recommended work-around for... William Hardwick August 27, 2012 9:41 AM
how to see the changes made..which url should I... Supriya Kare August 11, 2013 10:23 PM
1) The context hast to be changed in... Julian Dehne November 13, 2014 4:09 AM
in the ROOT.xml I meant to full path: ... Julian Dehne November 13, 2014 4:10 AM

What is the recommended work-around for hostConfigClass in Tomcat 7, since that attribute does not exist?
Posted on 8/27/12 9:41 AM.
how to see the changes made..which url should I use to see the changes..
when I use http://localhost:8080 it says page not found 404...so wht is the url
Posted on 8/11/13 10:23 PM.
1) The context hast to be changed in C:\dev\liferay\bundles\tomcat-7.0.42\conf\Catalina\localhost when using tomcat7
2) If you want to use the ecliple build mechanism and not ANT you have to do to steps:
- change app.server.tomcat.portal.dir to .../portal-web/docroot
- tell eclipse to compile your classes to .../portal/web/docroot/WEB-INF/classes
Posted on 11/13/14 4:09 AM.
in the ROOT.xml I meant to full path:

\tomcat-7.0.42\conf\Catalina\localhost\ROOT.xml
Posted on 11/13/14 4:10 AM in reply to Julian Dehne.