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

查看:138
本文介绍了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.

我将如何去吧?用war文件和 archetypeArtifactId = maven-archetype-webapp 一起创建项目,并从那里扩展?什么是最好的项目结构(和POM文件示例)?你在哪里粘贴与ear文件相关的部署描述符等?

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项目结构的资源目录中。

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天全站免登陆