问题
I'm packaging a JBoss service archive (SAR) and WAR together in an EAR with Maven for deployment to JBoss. The problem I have is that another standalone WAR running on this server calls a service provided by the aforementioned SAR on JBoss startup. Because JBoss deploys the standalone WAR before the EAR containing the SAR, the standalone WAR throws errors because the service it's calling has not been deployed yet.
Is there a way to get JBoss to deploy the EAR first? Is that even the correct approach?
One workaround would be to manually deploy the EAR first, then deploy the calling WAR, but I don't want to rely on deploying each manually because sometimes JBoss will simply be restarted.
回答1:
The solution that worked for me was to change the packaging. Instead of packaging the SAR and WAR in an EAR as I was doing originally, I packaged the WAR in the SAR.
.ear files get deployed several priorities below .sar files and given the fact that a .sar is intended to extend JBoss and is given a high deploy priority by default, I extrapolate that the results of lowering a .sar's priority can have unexpected consequences. In my case, another web application on the server calling the service provided by the .sar started failing.
To package the .war in with the .sar, I used the maven-dependency-plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-installed</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.company</groupId>
<artifactId>artifact-id</artifactId>
<type>war</type>
<version>1.0.0-BUILD-SNAPSHOT</version>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/${project.name}-${project.version}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
来源:https://stackoverflow.com/questions/22693884/war-deployment-to-jboss-fails-because-it-calls-a-sar-packaged-in-an-ear