【问题标题】:How to get rid of junctions using Maven如何使用 Maven 摆脱连接
【发布时间】:2014-05-19 20:57:55
【问题描述】:

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

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

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

谢谢

【问题讨论】:

    标签: java jsp maven junction


    【解决方案1】:

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

    假设我在这样的项目中有一些 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>
    

    现在SomeApp 的 war 文件将包含本地项目中包含的所有内容,以及我导入的混乱 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)
    

    【讨论】:

    • 是的,这似乎是一种正确的做法:)
    猜你喜欢
    • 2010-10-20
    • 2016-10-15
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多