I am using Struts 2 web application. It has lot of modules and functionality. I want to enable or disable (or remove) some modules based on customer requirement. But in Struts 2 under single WAR file deployment how can I make it as modular? Is it possible to take out some modules at deployment time??
Thanks in advance.
If you use Maven then you can exclude some classes / packages from being included in the resulting WAR and you can also have multiple targets and exclude different subsets of the code in that way.
This method assumes that you either keep the functionality separated into multiple "struts.xml" action definition files OR a if you use Struts2 conventions plugin with annotations etc then you end up with a very nice solution.
So, in pom.xml you have to first exclude all modules:
<build>
<finalName>badNameUseBuildProfileInstead</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/struts-module1.xml</exclude>
<exclude>**/struts-module2.xml</exclude>
<exclude>**/struts-module3.xml</exclude>
</excludes>
</resource>
</resources>
...
And then you make a build profile that includes the required modules:
...
<profiles>
<profile>
<id>web</id>
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/struts-web.xml</include>
</includes>
</resource>
</resources>
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With