Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 2 modular web application

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.

like image 303
kannan Avatar asked Sep 11 '26 19:09

kannan


1 Answers

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>
            ...
like image 172
Reigo Avatar answered Sep 15 '26 09:09

Reigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!