Answers:
您创建一个新项目。新项目是您的EAR组装项目,其中包含您的EJB项目和WAR项目的两个依赖项。
因此,您实际上在这里有三个Maven项目。一个EJB。一战。一个将两个部分拉在一起并形成耳朵的EAR。
部署描述符可以由maven生成,也可以放在EAR项目结构中的resources目录中。
maven-ear-plugin是用于配置它的工具,文档很好,但是如果您仍然想弄清楚maven的工作原理,还不清楚。
因此,作为示例,您可以执行以下操作:
<?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>
type
为ejb
<type>ejb</type>
'build.plugins.plugin.version' for org.apache.maven.plugins:maven-ear-plugin is missing
和'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing
,因此,您可能想更新您的其他好答案
对我帮助很大的是运行Maven原型:生成目标并从其中一种原型中进行选择,其中一些原型似乎会定期更新(特别是JBoss似乎维护良好)。
mvn archetype:generate
成百上千的原型出现在一个编号列表中供您选择(截至目前共有519个!)。该目标仍在运行,提示我通过输入数字或输入搜索字符串进行选择,例如:
513: remote -> org.xwiki.commons:xwiki-commons-component-archetype
514: remote -> org.xwiki.rendering:xwiki-rendering-archetype-macro
515: remote -> org.zkoss:zk-archetype-component
516: remote -> org.zkoss:zk-archetype-webapp
517: remote -> ru.circumflex:circumflex-archetype (-)
518: remote -> se.vgregion.javg.maven.archetypes:javg-minimal-archetype (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
我输入了搜索字符串“ ear”,将列表减少到仅8个项目(截止到今天):
Choose archetype:
1: remote -> org.codehaus.mojo.archetypes:ear-j2ee14 (-)
2: remote -> org.codehaus.mojo.archetypes:ear-javaee6 (-)
3: remote -> org.codehaus.mojo.archetypes:ear-jee5 (-)
4: remote -> org.hibernate:hibernate-search-quickstart (-)
5: remote -> org.jboss.spec.archetypes:jboss-javaee6-ear-webapp
6: remote -> org.jboss.spec.archetypes:jboss-javaee6-webapp-ear-archetype
7: remote -> org.jboss.spec.archetypes:jboss-javaee6-webapp-ear-archetype-blank
8: remote -> org.ow2.weblab.tools.maven:weblab-archetype-searcher
我选择了“ org.jboss.spec.archetypes:jboss-javaee6-ear-webapp”(在此示例中输入选择“ 5”)。
接下来,目标要求我输入groupId,artifactId,程序包名称等,然后生成了以下有据可查的示例应用程序:
[pgarner@localhost Foo]$ tree
.
|-- Foo-ear
| `-- pom.xml
|-- Foo-ejb
| |-- pom.xml
| `-- src
| |-- main
| | |-- java
| | | `-- com
| | | `-- foo
| | | |-- controller
| | | | `-- MemberRegistration.java
| | | |-- data
| | | | `-- MemberListProducer.java
| | | |-- model
| | | | `-- Member.java
| | | `-- util
| | | `-- Resources.java
| | `-- resources
| | |-- import.sql
| | `-- META-INF
| | |-- beans.xml
| | `-- persistence.xml
| `-- test
| |-- java
| | `-- com
| | `-- foo
| | `-- test
| | `-- MemberRegistrationTest.java
| `-- resources
|-- Foo-web
| |-- pom.xml
| `-- src
| `-- main
| |-- java
| | `-- com
| | `-- foo
| | `-- rest
| | |-- JaxRsActivator.java
| | `-- MemberResourceRESTService.java
| `-- webapp
| |-- index.html
| |-- index.xhtml
| |-- resources
| | |-- css
| | | `-- screen.css
| | `-- gfx
| | |-- banner.png
| | `-- logo.png
| `-- WEB-INF
| |-- beans.xml
| |-- faces-config.xml
| `-- templates
| `-- default.xhtml
|-- pom.xml
`-- README.md
32 directories, 23 files
在阅读了四个注释很好的POM文件之后,我几乎拥有了所需的所有信息。
./pom.xml
./Foo-ear/pom.xml
./Foo-ejb/pom.xml
./Foo-web/pom.xml
我做了一个github存储库,以显示我认为是好的(或最佳实践)启动项目结构...
https://github.com/StefanHeimberg/stackoverflow-1134894
一些关键字:
Maven输出:
Reactor Summary:
MyProject - BOM .................................... SUCCESS [ 0.494 s]
MyProject - Parent ................................. SUCCESS [ 0.330 s]
MyProject - Common ................................. SUCCESS [ 3.498 s]
MyProject - Persistence ............................ SUCCESS [ 1.045 s]
MyProject - Business ............................... SUCCESS [ 1.233 s]
MyProject - Web .................................... SUCCESS [ 1.330 s]
MyProject - Application ............................ SUCCESS [ 0.679 s]
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 8.817 s
Finished at: 2015-01-27T00:51:59+01:00
Final Memory: 24M/207M
------------------------------------------------------------------------
我一直在寻找一个完整的基于Maven的耳朵打包应用程序的端到端示例,但最后却偶然发现了这一点。说明说明通过CLI运行时选择选项2,但出于您的目的,请使用选项1。