Maven2:企业项目的最佳实践(EAR 文件) [英] Maven2: Best practice for Enterprise Project (EAR file)

查看:27
本文介绍了Maven2:企业项目的最佳实践(EAR 文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从 Ant 切换到 Maven,并且正在尝试找出设置基于 EAR 文件的企业项目的最佳实践?

I am just switching from Ant to Maven and am trying to figure out the best practice to set up a EAR file based Enterprise project?

假设我想创建一个非常标准的项目,其中包含用于 EJB 的 jar 文件、用于 Web 层的 WAR 文件和封装的 EAR 文件,以及相应的部署描述符.

Let's say I want to create a pretty standard project with a jar file for the EJBs, a WAR file for the Web tier and the encapsulating EAR file, with the corresponding deployment descriptors.

我该怎么办?使用 archetypeArtifactId=maven-archetype-webapp 像使用 war 文件一样创建项目,然后从那里扩展?什么是最好的项目结构(和 POM 文件示例)?你把与耳朵文件相关的部署描述符等贴在哪里?

How would I go about it? Create the project with archetypeArtifactId=maven-archetype-webapp as with a war file, and extend from there? What is the best project structure (and POM file example) for this? Where do you stick the ear file related deployment descriptors, etc?

感谢您的帮助.

推荐答案

您创建了一个新项目.新项目是您的 EAR 组装项目,其中包含您的 EJB 项目和 WAR 项目的两个依赖项.

You create a new project. The new project is your EAR assembly project which contains your two dependencies for your EJB project and your WAR project.

所以你实际上在这里有三个 Maven 项目.一个 EJB.一战.一个 EAR 将两个部分拉到一起并形成耳朵.

So you actually have three maven projects here. One EJB. One WAR. One EAR that pulls the two parts together and creates the ear.

部署描述符可以由maven生成,也可以放在EAR项目结构中的resources目录中.

Deployment descriptors can be generated by maven, or placed inside the resources directory in the EAR project structure.

maven-ear-plugin 是你用来配置它的, 文档 很好,但如果您仍在弄清楚 maven 一般是如何工作的,则不太清楚.

The maven-ear-plugin is what you use to configure it, and the documentation is good, but not quite clear if you're still figuring out how maven works in general.

举个例子,你可能会做这样的事情:

So as an example you might do something like this:

<?xml version="1.0" encoding="utf-8"?>
<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany</groupId>
  <artifactId>myEar</artifactId>
  <packaging>ear</packaging>
  <name>My EAR</name>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-ear-plugin</artifactId>
        <configuration>
          <version>1.4</version>
          <modules>
            <webModule>
              <groupId>com.mycompany</groupId>
              <artifactId>myWar</artifactId>
              <bundleFileName>myWarNameInTheEar.war</bundleFileName>
              <contextRoot>/myWarConext</contextRoot>
            </webModule>
            <ejbModule>
              <groupId>com.mycompany</groupId>
              <artifactId>myEjb</artifactId>
              <bundleFileName>myEjbNameInTheEar.jar</bundleFileName>
            </ejbModule>
          </modules>
          <displayName>My Ear Name displayed in the App Server</displayName>
          <!-- If I want maven to generate the application.xml, set this to true -->
          <generateApplicationXml>true</generateApplicationXml>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <encoding>UTF-8</encoding>
        </configuration>
      </plugin>
    </plugins>
    <finalName>myEarName</finalName>
  </build>

  <!-- Define the versions of your ear components here -->
  <dependencies>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>myWar</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>war</type>
    </dependency>
    <dependency>
      <groupId>com.mycompany</groupId>
      <artifactId>myEjb</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>ejb</type>
    </dependency>
  </dependencies>
</project>

这篇关于Maven2:企业项目的最佳实践(EAR 文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆