0

我很少有 Web 项目共享大约 95% 的 UI。目前我已经在我的 windows 机器上设置了联结,所以当我在 jsp 文件中进行更改时,所有项目都会立即获得相同的更新。所以我不必更新每个文件。

这种方法有效但很笨拙,因为我必须设置很痛苦且容易破坏的连接点。

如何使用 maven 解决此问题?我可以将整个 UI(jsp)打包到 .war 中并将其包含在每个项目中吗?这行得通吗?或者还有其他方法吗?

谢谢

4

1 回答 1

1

maven-war-plugin 将允许您创建一个包含所有 Web 文件的 war 文件,并将其用作依赖项目的覆盖。

假设我在这样的项目中有一些 ui 代码

src
 |-main
    |-webapp
        |-jsp
        |  |-thing1.jsp
        |  |-thing2.jsp
        |-WEB-INF
           |-web.xml

它的 pom.xml 看起来像这样:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>foo.bar.baz</groupId>
  <artifactId>big-messy-ui</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

在我的 UI 项目上进行 maven 安装后,我可以将它包含在这样的应用程序中:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>foo.bar.baz</groupId>
  <artifactId>some-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>
    <!-- include ui as an overlay -->
    <dependency>
      <groupId>foo.bar.baz</groupId>
      <artifactId>big-messy-ui</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>war</type>
    </dependency>
  </dependencies>

  <build>
    <finalName>SomeApp</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

现在,war 文件SomeApp将包含本地项目中包含的所有内容,以及我导入的凌乱 ui 中的所有内容:

SomeApp.war:

jsp
 |-thing1.jsp // from overlay
 |-thing2.jsp // from overlay
 |-plus anything from SomeApp's src/main/webapp/jsp
META-INF
 |-MANIFEST.MF
WEB-INF
 |-classes
 |   |-.class files from SomeApps's src/main/java
 |-web.xml (from SomeApp, the web.xml from the overlay is dropped)
于 2014-05-19T21:49:49.463 回答