3

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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
kannan
  • 571
  • 2
  • 6
  • 8
  • 2
    can you describe what you mean by modules? you can create modules as jars and use them as per your requirement – Umesh Awasthi Mar 06 '12 at 05:46
  • If you mean modules as in struts2 namespace, you probably want to get the actionmapping, and remove the one you don't need? That's the idea, but if you remove the mapping and if there is a call to the namespace mapping, wont it cause exception? – Jasonw Mar 06 '12 at 08:46

1 Answers1

2

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>
            ...
informatik01
  • 16,038
  • 10
  • 74
  • 104
Reigo
  • 285
  • 2
  • 9