在一个 Web 应用程序中从两场战争中构建两只耳朵

Building two ears from two wars in one webapp

一如既往,如果我提出了一个愚蠢的查询或一个很容易解决的问题,请原谅。在我正在进行的一个项目中,我被要求找出是否可以从一个 webapp 构建两个 wars。我可以通过以下方式解决这个问题:

网络项目

<artifactId>FacturaElectronica</artifactId>
<packaging>war</packaging>
<name>factElectronica - web</name>
<description>This is the web POM file</description>
<groupId>factElectronica-web</groupId>
<version>1.0-SNAPSHOT</version>

<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>       
            <plugin>         
                <artifactId>maven-install-plugin</artifactId>         
                <executions>           
                    <execution>             
                        <id>default-install</id>             
                        <phase>never</phase>           
                    </execution>         
                </executions>       
            </plugin>   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <executions>
                    <execution>
                      <id>default-war</id>
                      <phase>none</phase>
                      <configuration>
                        <finalName>unwanted</finalName>
                        <classifier>unwanted</classifier>
                      </configuration>
                    </execution>
                    <execution>
                        <id>facturaelectronicafija</id>
                        <phase>install</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <classifier>facturaelectronicafija</classifier>
                            <webResources>
                                <resource>
                                    <filtering>true</filtering>
                                    <directory>src/main/webapp</directory>
                                    <includes>
                                        <include>**</include>
                                    </includes>
                                </resource>
                                <resource>
                                    <directory>src/main/webapp</directory>
                                </resource>
                            </webResources>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                            <archive>
                                <manifestEntries>
                                    <Dependencies>org.apache.santuario.xmlsec,org.apache.commons.codec,javax.ws.rs.api</Dependencies>
                                </manifestEntries>
                            </archive>
                        </configuration>
                    </execution>
                    <execution>
                        <id>facturaelectronicamovil</id>
                        <phase>install</phase>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <classifier>facturaelectronicamovil</classifier>
                            <webResources>
                                <resource>
                                    <filtering>true</filtering>
                                    <directory>src/main/webapp</directory>
                                    <includes>
                                        <include>**</include>
                                    </includes>
                                </resource>
                                <resource>
                                    <directory>src/main/webappFant</directory>
                                </resource>
                            </webResources>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                            <archive>
                                <manifestEntries>
                                    <Dependencies>org.apache.santuario.xmlsec,org.apache.commons.codec,javax.ws.rs.api</Dependencies>
                                </manifestEntries>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java/resources</directory>
            </resource>
        </resources>
    </build>

每个 war 都具有相同的 类,但 xhtml 文件不同。一个指向移动 phone 组件,另一个指向固定电话 phone 组件。

这样做之后,我意识到有必要为它们中的每一个构建一个耳朵,每个耳朵都有其根上下文并在 wildfly 中执行部署。但我找不到方法去做。一方面我不知道如何指向 webapp 执行中内置的 wars,另一方面我不知道这种方式是否只有一只耳朵或者有必要建造两个。如果有人可以帮助我,我将不胜感激。非常感谢!

更新

以我在此 link 中找到的示例为例:Maven ear plugin multiple artifacts content

我做了以下修改:

网络项目

<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>package-facturaelectronicafija</id>
                            <phase>package</phase>
                            <configuration>
                                <classifier>facturaelectronicafija</classifier>
                                <webappDirectory>${project.build.directory}/${project.build.finalName}-facturaelectronicafija</webappDirectory>
                                <webResources>
                                    <resource>
                                        <directory>src/main/webapp</directory>
                                    </resource>
                                </webResources>
                            </configuration>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>package-facturaelectronicamovil</id>
                            <phase>package</phase>
                            <configuration>
                                <classifier>facturaelectronicamovil</classifier>
                                <webappDirectory>${project.build.directory}/${project.build.finalName}-facturaelectronicamovil</webappDirectory>
                                <webResources>
                                    <resource>
                                        <directory>src/main/webappFant</directory>
                                    </resource>
                                </webResources>
                            </configuration>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <finalName>FacturaElectronica</finalName> 
     </build>
</project>

耳朵计划

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>factElectronicaWeb-ear</groupId>
  <artifactId>factElectronicaWeb-ear</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>ear</packaging>
   
    <dependencies>
        <dependency>
            <groupId>factElectronica-web</groupId>
            <artifactId>FacturaElectronica</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>factElectronica-web</groupId>
            <artifactId>FacturaElectronica</artifactId>
            <version>1.0-SNAPSHOT</version>
            <classifier>facturaelectronicafija</classifier>
            <scope>provided</scope>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>factElectronica-web</groupId>
            <artifactId>FacturaElectronica</artifactId>
            <classifier>facturaelectronicamovil</classifier>
            <version>1.0-SNAPSHOT</version>
            <scope>provided</scope>
            <type>war</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <!-- <groupId>org.apache.maven.plugins</groupId> -->
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>package-facturaelectronicafija</id>
                        <phase>package</phase>
                        <configuration>
                            <workDirectory>target/facturaelectronicafija</workDirectory>
                            <classifier>facturaelectronicafija</classifier>
                            <version>8</version>
                            <modules>
                                <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicafija</classifier>
                                    <contextRoot>/FacturaElectronica</contextRoot>
                                    <bundleFileName>/FacturaElectronica.war</bundleFileName>
                                </webModule>
                            </modules>
                        </configuration>
                        <goals>
                            <goal>ear</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>package-facturaelectronicamovil</id>
                        <phase>package</phase>
                        <configuration>
                            <workDirectory>target/facturaelectronicamovil</workDirectory>
                            <classifier>facturaelectronicamovil</classifier>
                            <version>8</version>
                            <modules>
                                <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicamovil</classifier>
                                    <contextRoot>/FacturaElectronica</contextRoot>
                                    <bundleFileName>/FacturaElectronica.war</bundleFileName>
                                </webModule>
                            </modules>
                        </configuration>
                        <goals>
                            <goal>ear</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <finalName>FacturaElectronica</finalName>
    </build>
</project>

现在执行已完成,maven 创建了三个耳朵,第一个称为“FacturaElectronica”,我创建它是为了测试它是否确实有效。问题是三只耳朵和《FacturaElectronica》的内容一模一样。我想是因为maven没有找到对wards“facturaelectronicafija”和“facturaelectronicafija”的依赖。可能是因为当我在执行中创建这些 WAR 时,我无法向它们添加版本。有人可以澄清一下吗?非常感谢!

我会创建一个多模块项目,其中每个 WAR 和每个 EAR 都是单独的模块。

类 将是两个 WAR 模块中使用的 JAR 模块

我不得不进行一些更正,但我设法让它按预期工作。

网络项目

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
        <pluginManagement>
            <plugins>
                <plugin>         
                    <artifactId>maven-install-plugin</artifactId>         
                    <executions>           
                        <execution>             
                            <id>default-install</id>             
                            <phase>never</phase>           
                        </execution>         
                    </executions>       
                </plugin>   
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>default-war</id>
                            <phase>none</phase>
                            <configuration>
                                <finalName>unwanted</finalName>
                                <classifier>unwanted</classifier>
                            </configuration>
                        </execution>
                        <execution>
                            <id>package-facturaelectronicafija</id>
                            <phase>package</phase>
                            <configuration>
                                <classifier>facturaelectronicafija</classifier>
                                <webappDirectory>${project.build.directory}/${project.build.finalName}-facturaelectronicafija</webappDirectory>
                                <webResources>
                                    <resource>
                                        <directory>src/main/webapp</directory>
                                    </resource>
                                </webResources>
                            </configuration>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>package-facturaelectronicamovil</id>
                            <phase>package</phase>
                            <configuration>
                                <classifier>facturaelectronicamovil</classifier>
                                <webappDirectory>${project.build.directory}/${project.build.finalName}-facturaelectronicamovil</webappDirectory>
                                <webResources>
                                    <resource>
                                        <directory>src/main/webappFant</directory>
                                    </resource>
                                </webResources>
                            </configuration>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <finalName>FacturaElectronica</finalName>
     </build>

存在默认安装 运行,因此不会创建默认 war 基础。

耳朵计划

<modelVersion>4.0.0</modelVersion>
  <groupId>factElectronicaWeb-ear</groupId> 
  <artifactId>factElectronicaWeb-ear</artifactId>
  <version>0.0.1-SNAPSHOT</version> 
  <packaging>ear</packaging>
    
    <dependencies>
        
        <dependency>
            <groupId>factElectronica-web</groupId>
            <artifactId>FacturaElectronica</artifactId>
            <version>1.0-SNAPSHOT</version>
            <classifier>facturaelectronicafija</classifier>
            <scope>compile</scope>
            <type>war</type>
        </dependency>
         
        <dependency>
            <groupId>factElectronica-web</groupId>
            <artifactId>FacturaElectronica</artifactId>
            <classifier>facturaelectronicamovil</classifier>
            <version>1.0-SNAPSHOT</version>
            <scope>compile</scope>
            <type>war</type>
        </dependency>
        
    </dependencies>
    
    <build>
        <plugins>
            <plugin>         
                <artifactId>maven-install-plugin</artifactId>         
                <executions>           
                    <execution>             
                        <id>default-install</id>             
                        <phase>never</phase>           
                    </execution>         
                </executions>       
            </plugin>   
            <plugin>
                <groupId>org.apache.maven.plugins</groupId> 
                <artifactId>maven-ear-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                      <id>default-ear</id>
                      <phase>none</phase>
                      <configuration>
                        <finalName>unwanted</finalName>
                        <classifier>unwanted</classifier>
                      </configuration>
                    </execution>
                    
                    <execution>
                        <id>package-facturaelectronicafija</id>
                        <phase>package</phase>
                        <configuration>
                            <workDirectory>target/facturaelectronicafija</workDirectory>
                            <classifier>facturaelectronicafija</classifier>
                            <version>8</version>
                            <modules>
                                <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicafija</classifier>
                                    <contextRoot>/FacturaElectronica</contextRoot>
                                    <bundleFileName>/FacturaElectronica-facturaelectronicafija.war</bundleFileName>
                                </webModule>
                                 <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicamovil</classifier>
                                   <excluded>true</excluded>
                                 </webModule>
                            </modules>
                        </configuration>
                        <goals>
                            <goal>ear</goal>
                        </goals>
                    </execution>
                    
                    <execution>
                        <id>package-facturaelectronicamovil</id>
                        <phase>package</phase>
                        <configuration>
                            <workDirectory>target/facturaelectronicamovil</workDirectory>
                            <classifier>facturaelectronicamovil</classifier>
                            <version>8</version>
                            <modules>
                                <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicamovil</classifier>
                                    <contextRoot>/DetalleFactura</contextRoot>
                                    <bundleFileName>/FacturaElectronica-facturaelectronicamovil.war</bundleFileName>
                                </webModule>
                                 <webModule>
                                    <groupId>factElectronica-web</groupId>
                                    <artifactId>FacturaElectronica</artifactId>
                                    <classifier>facturaelectronicafija</classifier>
                                   <excluded>true</excluded>
                                 </webModule>
                            </modules>
                        </configuration>
                        <goals>
                            <goal>ear</goal>
                        </goals>
                    </execution>
                    
                </executions>
            </plugin>
        </plugins>
        <finalName>FacturaElectronica</finalName>
    </build>

以前依赖项只生成一个元 inf 文件,这是因为它们具有提供的范围,当您切换到编译时它可以正常工作。

<dependency>
                <groupId>factElectronica-web</groupId>
                <artifactId>FacturaElectronica</artifactId>
                <classifier>facturaelectronicamovil</classifier>
                <version>1.0-SNAPSHOT</version>
                <scope>compile</scope>
                <type>war</type>
            </dependency>