java 如何配置依赖于ejb jar的war并结合创建ear文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16383877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 22:49:41  来源:igfitidea点击:

how to configure war dependent on ejb jar and create ear file combinedly

javamaven

提问by developer

I am new to Maven and also learning it. I have two projects in eclipse one is retailproducts which contains UI stuff and other project is ejb project retailservice. I written separate pom files for both the projects and able to generate war and jar files. What i have to do is.

我是 Maven 的新手,也在学习它。我在 Eclipse 中有两个项目,一个是包含 UI 内容的零售产品,另一个项目是 ejb 项目零售服务。我为这两个项目编写了单独的 pom 文件,并且能够生成 war 和 jar 文件。我必须做的是。

a) I have to configure jar file in war file as jar file contains ejb stuff which is required by webappliction
b) after creating war file i have to create ear file which will have war file in turn jar file.

a)我必须在war文件中配置jar文件,因为jar文件包含webappliction所需的ejb内容
b)创建war文件后我必须创建ear文件,该文件将依次包含war文件和jar文件。

how can I do this.

我怎样才能做到这一点。

I am providing both the pom.xmls here.

我在这里提供了 pom.xmls。

<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>RetailProducts</groupId>
  <artifactId>RetailProducts</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name>RetailProducts</name>

  <dependencies>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.1.7</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.1.7</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
        </dependency>
                <!-- Tomcat 6 need this -->
        <dependency>
            <groupId>com.sun.el</groupId>
            <artifactId>el-ri</artifactId>
            <version>1.0</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>JavaServerFaces</finalName>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>2.1.1</version>
      <!-- <configuration> section added to pick up the WEB-INF/web.xml inside WebContent -->
      <configuration>
         <webResources>
            <resource>
               <directory>WebContent</directory>
            </resource>
         </webResources>
      </configuration>
   </plugin>
        </plugins>
    </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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>RetailService</groupId>
  <artifactId>RetailService</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>RetailService</name>
  <dependencies>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.15</version>
        <exclusions>
            <exclusion>
                <groupId>javax.mail</groupId>
                <artifactId>mail</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>3.6.10.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency> 
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.8</version>
    </dependency>    
    <dependency>
        <groupId>javax.ejb</groupId>
        <artifactId>ejb-api</artifactId>
        <version>3.0</version>
        <scope>provided</scope>
    </dependency>
  </dependencies> 
  <build>
    <sourceDirectory>ejbModule</sourceDirectory>
    <resources>
      <resource>
        <directory>ejbModule</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

回答by UnclickableCharacter

When building Java EE 5.0 application containing both WAR and EJB modules you usually have 3 Maven modules that define:

在构建包含 WAR 和 EJB 模块的 Java EE 5.0 应用程序时,您通常有 3 个 Maven 模块,它们定义:

  1. Web application
  2. EJBs
  3. EAR
  1. Web应用程序
  2. EJB
  3. 耳朵

You have first two but don't have EAR module. It should look something like this:

您有前两个,但没有 EAR 模块。它应该是这样的:

<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>Retail</groupId>
    <artifactId>RetailEAR</artifactId>
    <packaging>ear</packaging>
    <version>0.0.1-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.8</version>
                <configuration>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <skinnyWars>true</skinnyWars>
                    <version>5</version>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>RetailService</groupId>
            <artifactId>RetailService</artifactId>
            <type>ejb</type>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>RetailProducts</groupId>
            <artifactId>RetailProducts</artifactId>
            <type>war</type>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

Then when you package EAR module it handles dependencies for web application. The parameter skinnyWarscontrols if dependencies should be duplicated inside WAR or not. Usually you don't want them inside WAR since they are accessible to web application from EAR itself.

然后,当您打包 EAR 模块时,它会处理 Web 应用程序的依赖项。该参数skinnyWars控制是否应在 WAR 内复制依赖项。通常您不希望它们在 WAR 中,因为它们可以从 EAR 本身被 Web 应用程序访问。