java - Best practices for sharing web-tier code (Controllers and JSPs) between similar web apps -


i'm working on rewriting aging web applications. there 2 in particular very, similar, yet share no code today , aim fix that.

the projects being rewritten maven, spring mvc, , sitemesh.

model tier code easy enough share using jars. don't know of ways share common web-tier code (jsps , controllers) between similar apps.

here's background. these apps webstores. 1 normal store (think amazon.com) user can sign into, search products, add shopping cart, , check out. other same thing, it's punchout site. product browse , shopping cart portions identical. sign in , checkout, however, different.

i'm oversimplifying, it's enough illustrate problem. there's significant portion of web-tier code in product browse , shopping cart sections should able shared between two.

i don't think it's possible have same war file running either "mode" based on environment variable or settings different database. 1 of differences different spring security config. preferable leave other site's sign-in , checkout controllers out of component-scan nobody can somehow cross on wrong 1 url manipulation.

i started using maven profiles , filtering keep 2 different config sets (web.xml, spring configs, etc.) in same war project. based on maven profile selected, resulting war built different config set (and different name clarity). violates maven principal 1 pom produces 1 artifact.

is there better way this? maven war overlays? see people talking using overlays share common resources css, js, images, , common jsps. don't see mention sharing classes controllers way.

i push controller classes down jars, logically seems should stay respective jsps. , jsps can't pushed down jars (right?).

i thought making ear containing multiple war files -- 1 war common shopping experience, , war appropriate sign-in , checkout. believe session can shared between 2 wars in same ear, i'm not sure if plays nice spring's session-scope beans. hear they're not stored in session. i'd have figure out sitemesh decorators being used header/footer. same sitemesh config , resources need copied both wars, right? in end, shopping war artifact still different in each circumstance.

i have believe other people have dealt before. thinking wrong way? there common solution sort of thing?

good work doing battle against copy-paste. why it's hard share jsps? can copy them out of shared jar using maven dependency plugin:

 <plugin>          <groupid>org.apache.maven.plugins</groupid>          <artifactid>maven-dependency-plugin</artifactid>          <version>2.4</version>          <executions>            <execution>              <id>unpack</id>              <phase>package</phase>              <goals>                <goal>unpack</goal>              </goals>              <configuration>                <artifactitems>                  <artifactitem>                    <groupid>com.example</groupid>                    <artifactid>webapp-common</artifactid>                    <version>1.0-snapshot</version>                    <outputdirectory>[target jsp directory]</outputdirectory>                    <includes>**/*.jsp</includes>                  </artifactitem>                </artifactitems>              </configuration>            </execution>          </executions>        </plugin> 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -