Suppose I have two web apps to deploy in Tomcat 6, packed as, let us say, A.war
and B.war
. Is there a way to force Tomcat, when restarting, to:
- load
B
beforeA
? or - load
A
after everything else? or - make
A
loadable only afterB
is loaded - that is, makeB
a dependency ofA
?
These are the questions. Below comes a background that may be too complex but also very useful.
Background
I am trying to deploy some portlets in Liferay. These portlets are legacy code made by people who did not knew a lot about how Liferay works and made, let us say, "amazing" decisions, such as to map Liferay Service Builder entity tables to new classes. This does not come too much in case, actually, but someone who knows Liferay may understand my point a bit better.
These portlets are seamed by Spring and mapped to database by Hibernate. To avoid the annoying requirement of editing context.xml
(which is tiresome, error prone, easily forgettable, makes the persistence layer slow as hell etc.) I provided the 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 datasource of the Entity Manager Factory:
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="liferayDataSource"/>
<property name="persistenceUnitName" value="liferay-db" />
</bean>
If I have the Liferay running and I deploy my portlets, it runs without problem because the Liferay resources are already available. The problem is, when I restart Liferay these portlets are loaded before the Liferay app going up, so the InfrastructureUtil
class is not even loaded yet. So, I want to postpone the loading of the portlets.
I noted that each 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 is what determines the order, since it forces an alphabetical sorting of applications. Is that true? Can I set this number?
Of course, I am receptive to any solution but I am really curious about the possibilities of defining an ordering of application loading in Tomcat.