How can I define the loading order of a context in Tomcat or define some hierarchy of dependencies between contexts?

Suppose I have two web applications to deploy to Tomcat 6, packaged as, say, A.war

and B.war

. Is there a way to force Tomcat on restart:

  • load B

    before A

    ? or
  • load A

    after everything else? or
  • make is A

    loaded only after loading B

    , i.e. makes a B

    dependency on A

    ?

These are questions. Below is a background that can be overly complex but also very useful.

Background

I am trying to deploy some portlets in Liferay. These portlets are legacy code made by people who knew little about how Liferay works and what makes, say, β€œamazing” solutions, such as mapping Liferay Service Builder entity tables to new classes. It's not really that much, but someone who knows Liferay might understand my point a little better.

These portlets are Spring bound and mapped to the database using Hibernate. To avoid annoying editing requirements context.xml

(which is tedious, prone to errors, easily forgettable, makes the save layer slow as hell, etc.). I provided Liferay datasource as a new bean ...

<bean id="liferayDataSource" 
    class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
    <property name="targetDataSource">
        <bean
            class="com.liferay.portal.kernel.util.InfrastructureUtil"
            factory-method="getDataSource" />
    </property>
</bean>

      

... and used this new bean as the Entity Manager Factory data source:

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="liferayDataSource"/>
    <property name="persistenceUnitName" value="liferay-db" />
</bean>

      

If I have Liferay running and I deploy portlets, it works without issue because Liferay resources are already available. The problem is that when I restart Liferay, these portlets are loaded before the Liferay application grows, so the class InfrastructureUtil

has not been loaded yet. So, I want to defer the loading of the portlets.

I noticed that every application has a directory under $CATALINA_HOME/temp/

, usually called something like 0-this-annoying-portlet

, 2-that-weird-portlet

etc. I believe the number at the beginning determines the order, since it forces sorting alphabetically. Is that true? Can I set this number?

Of course I'm susceptible to any solution, but I'm really curious about how to determine the order in which applications are loaded in Tomcat.

+3


source to share


3 answers


The problem was that in Liferay 6.0 SP2 Tomcat was deploying an XML context file for each portlet. So when I deployed mine annoying-portlet

, a file is created $TOMCAT/conf/Catalina/localhost/annoying-portlet.xml

. When Tomcat is restarted, these XML context files are read, the corresponding projects are loaded (alphabetically by the way), and the portlet is launched before Liferay, whose context name is ROOT

.

As clear from the first link by @MarceloBezerra, $TOMCAT/conf/Catalina/localhost/annoying-portlet.xml

will take precedence (in the sense that all contexts with a file in $TOMCAT/conf/Catalina/localhost/

will be loaded before contexts that only have a directory in $TOMCAT/webapps

. Is to prevent the file from being deployed $TOMCAT/conf/Catalina/localhost/annoying-portlet.xml

.



How to do it? After some conversation with the great Liferay staff, they found that XML context expansion could be blocked by adding an attribute deployXML="false"

to an element Host

from $TOMCAT_HOME/conf/server.xml

:

<Host autoDeploy="true" 
    appBase="webapps" name="localhost" unpackWARs="true" 
    xmlNamespaceAware="false" xmlValidation="false">

      

+1


source


+2


source


Liferay can be force-loaded by the first application defining its context in the $ TOMCAT / conf / server.xml file, inside a tag:

<Host autoDeploy="true" 
appBase="webapps" name="localhost" unpackWARs="true" 
xmlNamespaceAware="false" xmlValidation="false">
   ....
   <Context path="" crossContext="true" docBase="ROOT">
       ....
   </Context>
   ....
</Host>

      

And by deleting the file $ TOMCAT / conf / Catalina / localhost / ROOT.xml

+1


source







All Articles