title: Wildfly/JBoss deployment startup order
body: <p>We use a service orientated architecture approach where we have some core services used by other services.  On startup, our services usually load up a cache of data from the core services so that it's available when a request comes in or scheduled tasks run.</p>
  
  <p><strong>I'm using Wildfly 8.2.0 and have Project A which depends on Project B (both are .war's).  Project A needs to wait for Project B to be loaded in order to start up.</strong></p>
  
  <p>Here is jboss-deployment-structure.xml in project B:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"&gt;
     &lt;deployment&gt;
        &lt;module-alias name="deployment.projectB"/&gt;
     &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt; 
  </code></pre>
  
  <p><em>On a side note, <code>module-alias</code> is used because project B is a war with a name like "projectB-2.0.0.war" but I don't want to care about the version number when I specify the dependency.</em></p>
  
  <p>Here is jboss-deployment-structure.xml in project A:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"&gt;
     &lt;deployment&gt;
        &lt;dependencies&gt;
           &lt;module name="deployment.projectB" /&gt;
        &lt;/dependencies&gt;
     &lt;/deployment&gt;
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p><strong>What I would like: if A and B are on the same Wildfly server, A needs to wait for B to start.  If A and B are on separate servers, they should start immediately.</strong></p>
  
  <p>Would optional dependencies accomplish this?  Like:</p>
  
  <pre><code>  &lt;dependencies&gt;
       &lt;module name="deployment.projectB" optional="true" /&gt;
    &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>I just set up <code>optional="true"</code> with A and B on the same server, and in this test, A and B are starting up at the same time (in the logs, I'm seeing EJB JNDI bindings being listed in pretty random order: B, A, B, B, B, B, B, A, A).  By "JNDI bindings", I mean that the logs are saying "JNDI bindings for session bean... are as follows".</p>
  
  <p>So maybe I'll have to throw away the <code>optional="true"</code> plan.</p>
  
  <p><strong>Update #2</strong></p>
  
  <p>Since project A has a dependency on project B, project B is getting loaded by project A's classloader, which isn't a good thing in this case (right off the bat I'm seeing that the wrong log4j.xml file is being used).</p>
  
  <p><strong>Update #3</strong></p>
  
  <p>Using jboss-deployment-structure.xml to influence load order may not be enough.  It looks like jboss-deployment-structure.xml can influence the order that classes load from the war's/ear's, but doesn't wait until their EJBs are started before starting to load the next deployment.</p>
  
  <p>Any other ideas?</p>
  
  <p>Thanks!</p>