用Maven打包成EAR部署JBoss


原文链接:http://blog.csdn.net/lishehe/article/details/41605753


基于原理的架构里面,考虑这次升级版本,可谓是一步一个脚印的向上走啊,可以说步步为坎,别人的知识,和自己的知识,相差很多啊,什么都懂点,但是具体没有使用,就理解不深刻了,心有余而力不足,所以一切我们自己来操作吧,可谓是体会深刻了,各种错,各种bug,是最好的学习进步的见证吧,


       最近的升级Jboss版本到EAP6.2,所谓是版本升级,内容新增很多啊,比5.1改观不少,现在我们遇到的问题是注入到EJB容器内部的实体在最后的持久化的数据库的时候报错了,实体找不到,报错如下:


[plain]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;">JBWEB000065: HTTP Status 500 - Request processing failed; nested exception is javax.ejb.EJBTransactionRolledbackException: Unknown entity: Jc.entity.Student  
  2. </span>  

在尝试几种方法解决,我做了使用达成EAR包的形成测试,具体步骤总结分享(0、1、2加载顺序)

0:封装了mgr接口和实体


1:

2:web层

我要把这三个包打成一个ear包,把相互的依赖关系打到一起,参考官网


新建一个Maven Project,写入pom文件内容

[java]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.tgb</groupId>  
  5.     <artifactId>lishehetestear</artifactId>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <packaging>ear</packaging>  
  8.     <build>  
  9.         <plugins>  
  10.             <plugin>  
  11.                 <artifactId>maven-ear-plugin</artifactId>  
  12.                 <version>2.9</version>  
  13.             </plugin>  
  14.         </plugins>  
  15.     </build>  
  16. </project></span>  

如果pom文件报错,那么安装一下 m2e-wtp这个插件,插件地址


插件装好之后,需要把需要打入的jar和war包都添加到里面来


[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><dependencies>  
  2.         <dependency>  
  3.             <groupId>com.tgb</groupId>  
  4.             <artifactId>lishehe_api</artifactId>  
  5.             <version>0.0.1-SNAPSHOT</version>  
  6.             <type>jar</type>  
  7.         </dependency>  
  8.   
  9.         <dependency>  
  10.             <groupId>com.tgb</groupId>  
  11.             <artifactId>lishehe_core</artifactId>  
  12.             <version>0.0.1-SNAPSHOT</version>  
  13.             <type>jar</type>  
  14.         </dependency>  
  15.         <dependency>  
  16.             <groupId>com.tgb</groupId>  
  17.             <artifactId>lishehe_war</artifactId>  
  18.             <version>0.0.1-SNAPSHOT</version>  
  19.             <type>war</type>  
  20.         </dependency>  
  21.     </dependencies></span>  



然后运行mvn的命令    ear: generate-application-xml,此命令是用来生成ear中的部署描述符的。


成功之后运行mvn的命令,ear:ear,,成功后,从target开发打包好的ear,发现要打包的几个包外,几个依赖的包也都在里面,ear提供的插件Creatin Skinny WARS



[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><span style="font-size:18px;"><plugin>  
  2.     <artifactId>maven-ear-plugin</artifactId>  
  3.     <version>2.9</version>  
  4.     <configuration>  
  5.         <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lishehe_*.war</packagingIncludes>  
  6.     </configuration>  
  7. </plugin></span></span>  

 注:上面这句话是说要将META-INF下(有application.xml等)及所有的lishehe开头的jar、war都打包进来。

       现在再来看,这样生成的ear包如下,现在就只剩下我们需要部署的jarwar



现在可以打成EAR包了,当我加载的时候出现了问题,空指针,Jboss按照字母加载,需要改成按照一定的依赖关系加载


只是在pom中对JBoss进行配置,还得将那些jar加载顺序写到application.xml文件(用ear:generate-application-xml生成的)里面。

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><span style="font-size:18px;"><plugins>  
  2.             <plugin>  
  3.                 <groupId>org.apache.maven.plugins</groupId>  
  4.                 <artifactId>maven-ear-plugin</artifactId>  
  5.                 <version>2.9</version>  
  6.                 <configuration>  
  7.                     <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lihehe_*.war</packagingIncludes>  
  8.                       
  9.                     <modules>  
  10.                         <jarModule>  
  11.                             <groupId>com.tgb</groupId>  
  12.                             <artifactId>lishehe_api</artifactId>  
  13.                             <includeInApplicationXml>true</includeInApplicationXml>  
  14.                         </jarModule>  
  15.                         <jarModule>  
  16.                             <groupId>com.tgb</groupId>  
  17.                             <artifactId>lishehe_core</artifactId>  
  18.                             <includeInApplicationXml>true</includeInApplicationXml>  
  19.                         </jarModule>  
  20.                         <webModule>  
  21.                             <groupId>com.tgb</groupId>  
  22.                             <artifactId>lishehe_war</artifactId>  
  23.                               
  24.                         </webModule>  
  25.                     </modules>  
  26.   
  27.   
  28.                 </configuration>  
  29.   
  30.             </plugin>  
  31.         </plugins></span></span>  
application.xml中文件生成是

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE application PUBLIC  
  3.     "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN"  
  4.     "http://java.sun.com/dtd/application_1_3.dtd">  
  5. <application>  
  6.   <display-name>lishehetestear</display-name>  
  7.   <module>  
  8.     <java>lishehe_api-0.0.1-SNAPSHOT.jar</java>  
  9.   </module>  
  10.   <module>  
  11.     <java>lishehe_core-0.0.1-SNAPSHOT.jar</java>  
  12.   </module>  
  13.   <module>  
  14.     <web>  
  15.       <web-uri>lishehe_war-0.0.1-SNAPSHOT.war</web-uri>  
  16.       <context-root>/lishehe_war</context-root>  
  17.     </web>  
  18.   </module>  
  19. </application></span></span>  


全的pom内容

[html]  view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><span style="font-size:18px;"><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.tgb</groupId>  
  5.     <artifactId>lishehetestear</artifactId>  
  6.     <version>0.0.1-SNAPSHOT</version>  
  7.     <packaging>ear</packaging>  
  8.     <url>http://maven.apache.org</url>  
  9.   
  10.   
  11.   
  12.     <dependencies>  
  13.         <dependency>  
  14.             <groupId>com.tgb</groupId>  
  15.             <artifactId>lishehe_api</artifactId>  
  16.             <version>0.0.1-SNAPSHOT</version>  
  17.             <type>jar</type>  
  18.         </dependency>  
  19.   
  20.         <dependency>  
  21.             <groupId>com.tgb</groupId>  
  22.             <artifactId>lishehe_core</artifactId>  
  23.             <version>0.0.1-SNAPSHOT</version>  
  24.             <type>jar</type>  
  25.         </dependency>  
  26.         <dependency>  
  27.             <groupId>com.tgb</groupId>  
  28.             <artifactId>lishehe_war</artifactId>  
  29.             <version>0.0.1-SNAPSHOT</version>  
  30.             <type>war</type>  
  31.         </dependency>  
  32.     </dependencies>  
  33.     <build>  
  34.         <plugins>  
  35.             <plugin>  
  36.                 <groupId>org.apache.maven.plugins</groupId>  
  37.                 <artifactId>maven-ear-plugin</artifactId>  
  38.                 <version>2.9</version>  
  39.                 <configuration>  
  40.                     <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lihehe_*.war</packagingIncludes>  
  41.                     <jboss>  
  42.                         <version>5</version>  
  43.                         <module-order>strict</module-order>  
  44.                     </jboss>  
  45.                     <modules>  
  46.                         <jarModule>  
  47.                             <groupId>com.tgb</groupId>  
  48.                             <artifactId>lishehe_api</artifactId>  
  49.                             <includeInApplicationXml>true</includeInApplicationXml>  
  50.                         </jarModule>  
  51.                         <jarModule>  
  52.                             <groupId>com.tgb</groupId>  
  53.                             <artifactId>lishehe_core</artifactId>  
  54.                             <includeInApplicationXml>true</includeInApplicationXml>  
  55.                         </jarModule>  
  56.                         <webModule>  
  57.                             <groupId>com.tgb</groupId>  
  58.                             <artifactId>lishehe_war</artifactId>  
  59.                               
  60.                         </webModule>  
  61.                     </modules>  
  62.   
  63.   
  64.                 </configuration>  
  65.   
  66.             </plugin>  
  67.         </plugins>  
  68.     </build>  
  69.   
  70. </project></span></span>  


剩下的就是部署了,直接扔到Jboss里面即可,


总结

       这个时候深刻体会到英语很重要啊,细心的深入的去学习,查资料(外网的靠谱)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值