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

淺唱寂寞╮ 提交于 2019-12-02 23:52:05

Good work doing battle against copy-paste. Why do you say it's hard to share JSPs? You can copy them out of a shared jar using the 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>

My preferred option in this cases is put all related files (controllers, js, images...) in a jar. But the problem here is the use of JSP files: there is no easy way of using them if they are in a jar. But with other view technologies such as Velocity or Freemarker this is possible in an easy way, among other advantages. I don't know if this can lead you to too much work, but for a new project with these needs it is the best option.

Larry L

We are using Subversion here, and use svn:externals (kind of like symbolic links) in order to share certain common code (mostly .jsp files) between projects. Works fairly well, we were using OC4J which actually has a way to share .jsp's between multiple projects, but since we are currently moving towards Tomcat (or something else) I wanted to come up with a container agnostic way to do it.

JZ.Hunt

Sinuhepop is right ,but his answer not perfect.

Here is the perfect answer. you have to refer the follow url, it can hep you.

click here

in the url page, the example for the property content box is not exact, you follow me:

if need to share a file:

a.jsp  svn://myhome.com/svn/myproject/trunk/a.jsp

if need to share a folder:

xml  svn://myhome.com/svn/myproject/trunk/xml
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!