有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

针对两个客户机的SpringJavaWeb应用程序项目开发

我正在开发一个基于Spring(MVC)、Hibernate和PostgreSQL(使用Maven)的web项目。现在,我正试图找到一位新客户,他要求在应用程序的几个部分有所不同。我已经阅读了Sonatype的Maven权威指南,以了解多模块Maven项目,但其中一个最重要的问题尚未得到回答:如何在多个模块/项目上共享公共视图组件,并根据我想要构建的客户将其集成?服务层非常清晰,但我不知道如何共享jsp/jspf文件,以及在构建特定的客户模块(这取决于公共模块)时如何将它们与自定义文件合并

您将如何避免简单地克隆常用代码


共 (2) 个答案

  1. # 1 楼答案

    I can't figure out how to share jsp/jspf files and merge them with the custom files when building the specific customer-module (which then depends on the common-module).

    这看起来是Overlays的一个很好的用例

  2. # 2 楼答案

    您可以将公共组件放在库项目中,并根据需要使用dependency:unpackdependency:unpack-dependencies对它们进行解压缩

    例如,您的项目布局如下:

    root
     |____ common-lib (jar, contains common java code)
     |____ common-gui (jar, contains only non-java stuff like js, jsp, css etc) 
     |____ client1    (war)
     |____ client2    (war)
    

    client1和client2对公共lib都有一个常规的compile依赖项,但对公共gui只有一个provided依赖项(如果使用dependency:unpack,它根本不必是项目依赖项)

    现在,您可以将这样的代码添加到客户端项目中:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>unpack-common-gui-elements</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>unpack</goal>
                </goals>
                <configuration>
                    <artifactItems>
                        <artifactItem>
                            <groupId>com.yourcompany</groupId>
                            <artifactId>common-gui</artifactId>
                            <version>${project.version}</version>
                            <type>jar</type>
                            <!   war assembly directory  >
                            <outputDirectory>
                                ${project.build.directory}/${project.build.finalName}
                            </outputDirectory>
                            <includes>**/*.jsp,**/*.css,**/*.js</includes>
                        </artifactItem>
                    </artifactItems>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    通过这种方式,您可以重用组件,但您始终可以选择将哪些组件分发给哪个客户机