gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:49:16 27 4
gpt4 key购买 nike

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

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

我该怎么做。

我在这里提供了两个 pom.xml。

<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>

最佳答案

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

  1. 网络应用
  2. EJB
  3. 耳朵

您有前两个但没有 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>

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

关于java - 如何配置依赖于ejb jar的war并结合创建ear文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16383877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com