Prior to Seam starting up we need to configure some stuff. To do this we make use of JBoss's ability to access System properties.
Note: This does have one drawback. Because we are using system properties the configured properties are accessable by any application running in the JBoss instance. This could cause trouble if multiple applications are looking up the same property key but need different values but could be worked around by prefixing your property names. Also I guess this could pose a minor security issue if you are sharing your JBoss instance with another application who you don't trust - this poses no issue for 99% of installations.JBoss allows you to access Java system properties using the following syntax:
${my-property-name:default-value}
This will cause the value of the system property named "my-property-name" to be used if it is defined or the "default-value" if it cannot be found.
<datasources>
<local-tx-datasource>
<jndi-name>myDatasource</jndi-name>
<connection-url>
jdbc:mysql://${datasource.url:localhost:3306/myschema}
</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>${datasource.username:myusername}</user-name>
<password>${datasource.password:secret}</password>
</local-tx-datasource>
</datasources>
This is great but defining system properties on the command line when you start JBoss would be tedious and hard to maintain.
-Dmyprop.1 -Dmyprop.2.....
is not an acceptable solution.
Thankfully JBoss comes to the rescue again. We can make use of the
SystemPropertiesService
. This JBoss service lets us define all of our properties in a standard Java properties file and the
SystemPropertiesService
will make all of these accessible as though they are system properties.
To make use of this service we need to configure
server/<server-name>/deploy/properties-service.xml
You are able to define properties as key/value pairs in this file directly but a better option is to define them in a properties file. To do this set the following:
<attribute name="URLList">
./data/system.properties
</attribute>
You can even specify urls such as
http://somehost/some-location.properties
so you could store your properties in a single location.
Now that is set up you can use it the same way in other places such as your
web.xml
and
application.xml
this allows you to tailor your application including things like context root.
For example to define your context root in your application.xml you can do something like this:
<context-root>${application.context.root:/site}</context-root>
Here if you have
application.context.root
defined it will be used or else the default value ("
/site
") will be used.
Defining deployment dependencies
The above works well but you may find that it doesn't always work. The reason for this is that sometimes the
SystemPropertiesService
has not finished initialising before your application is deployed. To fix this we can define your application to be dependent on the
SystemPropertiesService
.
You need to edit
server/<sever-name>/deployers/dependency-deployers-jboss-beans.xml
to make it look like the following:
<bean name="DependenciesParserDeployer" class="org.jboss.deployers.vfs.plugins.dependency.DependenciesParserDeployer">
<property name="stage"><inject bean="PreParseStage"/></property>
</bean>
<bean name="DependenciesMDDeployer" class="org.jboss.deployers.vfs.plugins.dependency.DependenciesMetaDataDeployer">
<property name="stage"><inject bean="PreParseStage"/></property>
</bean>
<bean name="DeploymentDependenciesDeployer" class="org.jboss.deployers.vfs.plugins.dependency.DeploymentDependencyDeployer">
<property name="stage"><inject bean="PreParseStage"/></property>
</bean>
<bean name="PreParseStage" class="org.jboss.deployers.spi.deployer.DeploymentStage">
<constructor>
<parameter class="java.lang.String">PreParse</parameter>
<parameter class="java.lang.String">Not Installed</parameter>
</constructor>
</bean>
Now in your ear you need to add a
jboss-dependency.xml
in the
META-INF
of your ear.
<dependency xmlns="urn:jboss:dependency:1.0">
<item whenRequired="Parse">jboss:type=Service,name=SystemProperties</item>
</dependency>
This will ensure your application starts after the
SystemPropertiesService
.