Maven2:企业项目最佳实践(EAR 文件)
我刚刚从 Ant 切换到 Maven,并试图找出建立基于 EAR 文件的企业项目的最佳实践?
假设我想创建一个相当标准的项目,其中包含用于 EJB 的 jar 文件、用于 Web 层的 WAR 文件和封装 EAR 文件以及相应的部署描述符。
我该怎么办呢? 使用 archetypeArtifactId=maven-archetype-webapp
创建项目,就像使用 war 文件一样,并从那里扩展? 对此最好的项目结构(和 POM 文件示例)是什么? 你把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?
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.
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?
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您创建一个新项目。 新项目是 EAR 程序集项目,其中包含 EJB 项目和 WAR 项目的两个依赖项。
所以这里实际上有三个 Maven 项目。 一个 EJB。 一场战争。 一个 EAR 将两个部分拉在一起并形成耳朵。
部署描述符可以由 maven 生成,或者放置在 EAR 项目结构中的资源目录中。
maven-ear-plugin 是您用来配置它的工具,文档 很好,但不太清楚您是否仍在了解 Maven 的总体工作原理。
举个例子,你可能会这样做:
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.
So you actually have three maven projects here. One EJB. One WAR. One EAR that pulls the two parts together and creates the ear.
Deployment descriptors can be generated by maven, or placed inside the resources directory in the EAR project structure.
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:
对我有很大帮助的是运行 Maven archetype:generate 目标并从其中一个原型中进行选择,其中一些原型似乎会定期更新(特别是 JBoss 似乎维护得很好)。
数百个原型出现在一个编号列表中可供选择(目前有 519 个!)。 仍在运行的目标提示我通过输入数字或输入搜索字符串来进行选择,例如:
我输入了搜索字符串“ear”,这将列表减少到只有 8 个项目(截至今天):
我选择了“org” .jboss.spec.archetypes:jboss-javaee6-ear-webapp”(在此示例中输入选择“5”)。
接下来,目标要求我输入 groupId、artifactId、包名称等,然后它生成以下记录良好的示例应用程序:
阅读了四个注释良好的 POM 文件后,我几乎有了所有我需要的信息。
What helped me a lot was to run the Maven archetype:generate goal and select from one of the archetypes, some of which seem to be updated regularly (in particular JBoss seems to be well maintained).
Hundreds of archetypes appeared in a numbered list from which to select (519 as of now!). The goal, still running, prompted me to make a selection by entering a number or entering a search string e.g.:
I entered the search string "ear," which reduced the list to only 8 items (as of today):
I selected "org.jboss.spec.archetypes:jboss-javaee6-ear-webapp" (by entering the selection "5" in this example).
Next, the goal asked me to enter the groupId, artifactId, package names, etc., and it then generated the following well-documented example application:
After reading the four POM files, which were well-commented, I had pretty much all the information I needed.
我制作了一个 github 存储库来展示我认为好的(或最佳实践)启动项目结构...
https://github .com/StefanHeimberg/stackoverflow-1134894
一些关键字:
Maven 输出:
i have made a github repository to show what i think is a good (or best practices) startup project structure...
https://github.com/StefanHeimberg/stackoverflow-1134894
some keywords:
Maven Output:
NetBeans IDE 自动定义的结构几乎与 Patrick Garner 建议的结构相似。 对于 NetBeans 用户
文件->新建项目 ->在左侧选择Maven,在右侧选择Maven Enterprise Application< /strong> 并按下一步 -> 询问 war、ejb 和设置的项目名称。
IDE 将自动为您创建结构。
NetBeans IDE automatically defines the structure which is almost similar to one suggested by Patrick Garner. For NetBeans users
File->New Project ->In left side select Maven and In right side select Maven Enterprise Application and press Next -> Asks for project names for both war,ejb and settings.
The IDE will automatically create the structure for you.
这是 maven-ear-plugin 部分的一个很好的示例。
您还可以检查作为示例的 maven 原型。 如果您只是运行 mvn archetype:generate 您将获得可用原型的列表。 其中之一是
This is a good example of the maven-ear-plugin part.
You can also check the maven archetypes that are available as an example. If you just runt mvn archetype:generate you'll get a list of available archetypes. One of them is
我一直在寻找完整的基于 maven 的ear-packaged应用程序的端到端示例,最后偶然发现了 这个。 说明显示通过 CLI 运行时选择选项 2,但出于您的目的,请使用选项 1。
I've been searching high and low for an end-to-end example of a complete maven-based ear-packaged application and finally stumbled upon this. The instructions say to select option 2 when running through the CLI but for your purposes, use option 1.