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,
. Is there a way to force Tomcat on restart:
after everything else? or
- make is
loaded only after loading
, i.e. makes a
These are questions. Below is a background that can be overly complex but also very useful.
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
(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
has not been loaded yet. So, I want to defer the loading of the portlets.
I noticed that every application has a directory under
, usually called something like
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.
source to share
The problem was that in Liferay 6.0 SP2 Tomcat was deploying an XML context file for each portlet. So when I deployed mine
, a file is created
. 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
As clear from the first link by @MarceloBezerra,
will take precedence (in the sense that all contexts with a file in
will be loaded before contexts that only have a directory in
. Is to prevent the file from being deployed
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
to an element
<Host autoDeploy="true" appBase="webapps" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
source to share
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
source to share