【问题标题】:Building both war and ear files for same project using maven使用 maven 为同一个项目构建 war 和 ear 文件
【发布时间】:2011-05-11 11:05:38
【问题描述】:


在我的项目中,我有与网络相关的东西(jsps、控制器、..)和 EJB bean。
现在我需要用网络相关的东西构建战争文件并将其部署到 tomcat 和
需要为 EJB 构建 ear 文件并使用 maven 将其部署到 jboss 中。

谁能建议我相应地修改 pom.xml 的解决方案。

谢谢你,
帕万

【问题讨论】:

    标签: java maven-2 ejb maven-plugin


    【解决方案1】:

    最好的方法是将您的项目拆分为多个子项目:一个构建 EJB,一个构建 WAR,第三个将它们打包在一起。这在Maven: The Complete Reference 中有描述,在Better Builds with Maven 中有一个示例。

    【讨论】:

    • 不,我们不能将源代码拆分为子项目。
    • @Pawan - 然后不要使用 Maven。我对此很认真:如果您不想按照开发人员的意图使用它,Maven 会让您的生活变得非常困难。您可能会更喜欢 Ant,使用 Maven Ant 任务检索依赖项。
    • 能否详细说明在这种情况下同时使用 Maven 和 Ant 任务?
    • @Pawan - 都在文档中:maven.apache.org/ant-tasks/index.html 祝你好运。
    • 感谢您的参考链接。
    【解决方案2】:

    您需要使用配置文件。在 pom.xml 中的每个配置文件中,您可以指定您喜欢的任何配置。该配置将在您运行 mvn -PyourProfileName 时应用。

    【讨论】:

    • 非常感谢您的回复。但是如果我们使用配置文件,我们需要多次运行 mvn 命令。那么,我们还有什么可以做的吗?
    【解决方案3】:

    您可以将所有内容都放在一个 pom.xml 中:

    首先,制作/使用您的标准“战争”pom.xml。

    创建文件夹“src/main/application/META-INF”。

    将耳朵相关的文件,如“application.xml”(强制)、“jboss-app.xml”和/或“jboss-deployment-structure.xml”放在那里。

    扩展你的 pom.xml:

    <resources>
        <resource>
            <directory>src/main/application</directory>
            <filtering>true</filtering>
            <includes>
                <include>META-INF/*.xml</include>
            </includes>
        </resource>
    </resources>
    

    还有:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <ear
                                destfile="${project.build.directory}/${project.build.finalName}.ear"
                                appxml="${project.build.outputDirectory}/META-INF/application.xml">
                                <fileset dir="${project.build.outputDirectory}"
                                    includes="META-INF/*.xml" excludes="META-INF/application.xml" />
                                <fileset dir="${project.build.directory}"
                                    includes="${project.build.finalName}.war" />
                            </ear>
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    

    提示:application.xml 应如下所示:

    <?xml version="1.0" encoding="UTF-8"?>
    <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
      <display-name>XXX.ear</display-name>
      <module>
        <web>
          <web-uri>XXX.war</web-uri>
          <context-root>XXX</context-root>
        </web>
      </module>
    </application>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-02
      • 2014-07-01
      • 2017-10-13
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 2011-08-09
      相关资源
      最近更新 更多