EAR项目构建的几种方式
2016-07-16 08:45
281 查看
PS:说实话,在写这篇帖子之前,我也没用过EAR,因此该贴仅是记录学习过程用~有什么不对的地方,或者欠缺的,还请各位看官斧正,先谢过各位了~~
一、基于传统WebProject方式
在eclipse中,右键new > project > Dynamic web project ,
在弹出的对话框中输入项目名称testWeb,注意,在EAR membership中勾选上“Add project to an EAR”,并输入准备创建的EAR的名称,例如TestEAR,
再创建几个Web project,此时可以选择需要加入的EAR的名称,这里,我们都选择TestEAR,
每个web project,我们都可以随意的写些测试页面,以供测试使用。
在TestEAR项目上,右键 > properties 弹出的面板中,进入 project facets条目,可以看到,该项目特征为EAR,且被选中。
在该EAR项目目录下的EarContent文件夹下创建META-INF/application.xml,该文件是设置ear打包时需要包含相关资源的配置文件。样例如下:
[html] view plain copy print?
<?xml version="1.0" encoding="UTF-8"?>
<application id="testEAR" version="1.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>TestEAR</display-name>
<module id="WebModule_testA">
<web>
<web-uri>testA.war</web-uri>
<context-root>.testA</context-root>
</web>
</module>
</application>
display-name设置部署显示的名称,module定义一个被包含的资源,可以是EJB的jar,也可以是一个子系统的war,上面这个例子中都是引入的war,因此用web作为标签。web-uri声明被引入的war路径,context-root声明访问路径(相对于该EAR项目)。
在TestEAR项目上右键 export 选择EAR file,即可导出ear文件,用压缩包程序打开TestEAR.ear文件可以看到该ear包含的war文件。
二、基于maven-ear-plugin插件构建EAR项目
1、创建一个maven webapp,将packaging类型选为ear
<packaging>ear</packaging>
2、添加包含的war、jar等依赖,如下:
[html] view plain copy print?
<dependency>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1</version>
<type>war</type>
</dependency>
3、添加maven-ear-plugin插件,并配置
[html] view plain copy print?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- 打包指定目录到lib -->
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<!-- 将多个war的共享包提取到父级别 -->
<skinnyWars>true</skinnyWars>
<modules>
<webModule>
<moduleId>webdemo-framework</moduleId>
<groupId>com.test</groupId>
<artifactId>framework</artifactId>
<bundleFileName>test-framework.war</bundleFileName>
</webModule>
<webModule>
<moduleId>webdemo-test</moduleId>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<bundleFileName>test.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
4、很大可能在配置完上面的内容后,pom文件会报错,例如:
Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-ear-plugin:2.10:generate-application-xml (execution: default-generate-application-xml, phase: generate-resources)
解决方案如下:(参考帖子>>传送门)
在plugins同级增加一组pluginManagement标签,在插件管理中,对lifecycle-mapping进行配置
[html] view plain copy print?
<build>
如此,可解除上述错误~
一、基于传统WebProject方式
在eclipse中,右键new > project > Dynamic web project ,
在弹出的对话框中输入项目名称testWeb,注意,在EAR membership中勾选上“Add project to an EAR”,并输入准备创建的EAR的名称,例如TestEAR,
再创建几个Web project,此时可以选择需要加入的EAR的名称,这里,我们都选择TestEAR,
每个web project,我们都可以随意的写些测试页面,以供测试使用。
在TestEAR项目上,右键 > properties 弹出的面板中,进入 project facets条目,可以看到,该项目特征为EAR,且被选中。
在该EAR项目目录下的EarContent文件夹下创建META-INF/application.xml,该文件是设置ear打包时需要包含相关资源的配置文件。样例如下:
[html] view plain copy print?
<?xml version="1.0" encoding="UTF-8"?>
<application id="testEAR" version="1.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>TestEAR</display-name>
<module id="WebModule_testA">
<web>
<web-uri>testA.war</web-uri>
<context-root>.testA</context-root>
</web>
</module>
<module id="WebModule_testB"> <web> <web-uri>testB.war</web-uri> <context-root>.testB</context-root> </web> </module> <module id="WebModule_testC"> <web> <web-uri>testC.war</web-uri> <context-root>.testC</context-root> </web> </module>
</application>
display-name设置部署显示的名称,module定义一个被包含的资源,可以是EJB的jar,也可以是一个子系统的war,上面这个例子中都是引入的war,因此用web作为标签。web-uri声明被引入的war路径,context-root声明访问路径(相对于该EAR项目)。
在TestEAR项目上右键 export 选择EAR file,即可导出ear文件,用压缩包程序打开TestEAR.ear文件可以看到该ear包含的war文件。
二、基于maven-ear-plugin插件构建EAR项目
1、创建一个maven webapp,将packaging类型选为ear
<packaging>ear</packaging>
2、添加包含的war、jar等依赖,如下:
[html] view plain copy print?
<dependency>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1</version>
<type>war</type>
</dependency>
3、添加maven-ear-plugin插件,并配置
[html] view plain copy print?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<!-- 打包指定目录到lib -->
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<!-- 将多个war的共享包提取到父级别 -->
<skinnyWars>true</skinnyWars>
<modules>
<webModule>
<moduleId>webdemo-framework</moduleId>
<groupId>com.test</groupId>
<artifactId>framework</artifactId>
<bundleFileName>test-framework.war</bundleFileName>
</webModule>
<webModule>
<moduleId>webdemo-test</moduleId>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<bundleFileName>test.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
4、很大可能在配置完上面的内容后,pom文件会报错,例如:
Maven Project Build Lifecycle Mapping Problem
Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-ear-plugin:2.10:generate-application-xml (execution: default-generate-application-xml, phase: generate-resources)
解决方案如下:(参考帖子>>传送门)
在plugins同级增加一组pluginManagement标签,在插件管理中,对lifecycle-mapping进行配置
[html] view plain copy print?
<build>
<pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <versionRange>[2.4.0,)</versionRange> <goals> <goal>generate-application-xml</goal> </goals> </pluginExecutionFilter> <action> <ignore /> </action> </pluginExecution> </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> </plugins> </pluginManagement> <plugins> </plugins> </build>
如此,可解除上述错误~
相关文章推荐
- Discuzx系统 CSS 编码规范,CSS属性书写顺序
- 【原创】基于Memcached 实现用户登录的Demo(附源码)
- OC 运行时机制的一些应用
- 深度学习,看论文之前我学了这些东西
- 复杂选择器 内容生成 多列 CSSHack(浏览器兼容)
- Nodejs之MEAN栈开发(七)---- 用Angular创建单页应用(下)
- PHP如何将session保存到memcached中?如何分布式保存PHP session
- mysql bin 安装
- POJ1200 Crazy Search
- 还原MySql数据库失败:max_allowed_packet 设置过小导致记录写入失败
- JDBC连接Sqlserver
- hidefocus小技巧
- 用CSS3实现旋转的CD
- Codeforces 650B Image Preview(尺取法)
- PHP将字符串首字母大小写转换
- hibernate联合主键生成策略以及一对多配置
- PHPThumb处理图片,生成缩略图,图片尺寸调整,图片截取,图片加水印,图片旋转
- 设置MySQL数据库名不区分大小写
- 关于增强现实(AR技术)的开源库推荐
- RTMP 封包详解