首页 > 代码库 > 用Maven打包成EAR部署JBoss
用Maven打包成EAR部署JBoss
基于原理的架构里面,考虑这次升级版本,可谓是一步一个脚印的向上走啊,可以说步步为坎,别人的知识,和自己的知识,相差很多啊,什么都懂点,但是具体没有使用,就理解不深刻了,心有余而力不足,所以一切我们自己来操作吧,可谓是体会深刻了,各种错,各种bug,是最好的学习进步的见证吧,
最近的升级Jboss版本到EAP6.2,所谓是版本升级,内容新增很多啊,比5.1改观不少,现在我们遇到的问题是注入到EJB容器内部的实体在最后的持久化的数据库的时候报错了,实体找不到,报错如下:
<span style="font-size:18px;">JBWEB000065: HTTP Status 500 - Request processing failed; nested exception is javax.ejb.EJBTransactionRolledbackException: Unknown entity: Jc.entity.Student </span>
在尝试几种方法解决,我做了使用达成EAR包的形成测试,具体步骤总结分享(0、1、2加载顺序)
0:封装了mgr接口和实体
1:
2:web层
我要把这三个包打成一个eao包,把相互的依赖关系打到一起,参考官网
新建一个Mavne Project,写入pom文件内容
<span style="font-size:18px;"><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>com.tgb</groupId> <artifactId>lishehetestear</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>ear</packaging> <build> <plugins> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.9</version> </plugin> </plugins> </build> </project></span>
如果pom文件报错,那么安装一下 m2e-wtp这个插件,插件地址
插件装好之后,需要把需要打入的jar和war包都添加到里面来
<span style="font-size:18px;"><dependencies> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_api</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_core</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_war</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> </dependencies></span>
然后运行mvn的命令 ear: generate-application-xml,此命令是用来生成ear中的部署描述符的。
成功之后运行mvn的命令,ear:ear,,成功后,从target开发打包好的ear,发现要打包的几个包外,几个依赖的包也都在里面,ear提供的插件Creatin Skinny WARS,
<span style="font-size:18px;"><span style="font-size:18px;"><plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.9</version> <configuration> <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lishehe_*.war</packagingIncludes> </configuration> </plugin></span></span>
注:上面这句话是说要将META-INF下(有application.xml等)及所有的lishehe开头的jar、war都打包进来。
现在再来看,这样生成的ear包如下,现在就只剩下我们需要部署的jar及war。
现在可以打成EAR包了,当我加载的时候出现了问题,空指针,Jboss按照字母加载,需要改成按照一定的依赖关系加载
只是在pom中对JBoss进行配置,还得将那些jar加载顺序写到application.xml文件(用ear:generate-application-xml生成的)里面。
<span style="font-size:18px;"><span style="font-size:18px;"><plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.9</version> <configuration> <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lihehe_*.war</packagingIncludes> <jboss> <version>5</version> <module-order>strict</module-order> </jboss> <modules> <jarModule> <groupId>com.tgb</groupId> <artifactId>lishehe_api</artifactId> <includeInApplicationXml>true</includeInApplicationXml> </jarModule> <jarModule> <groupId>com.tgb</groupId> <artifactId>lishehe_core</artifactId> <includeInApplicationXml>true</includeInApplicationXml> </jarModule> <webModule> <groupId>com.tgb</groupId> <artifactId>lishehe_war</artifactId> </webModule> </modules> </configuration> </plugin> </plugins></span></span>application.xml中文件生成是
<span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd"> <application> <display-name>lishehetestear</display-name> <module> <java>lishehe_api-0.0.1-SNAPSHOT.jar</java> </module> <module> <java>lishehe_core-0.0.1-SNAPSHOT.jar</java> </module> <module> <web> <web-uri>lishehe_war-0.0.1-SNAPSHOT.war</web-uri> <context-root>/lishehe_war</context-root> </web> </module> </application></span></span>
jboss-app.xml内容
<span style="font-size:18px;"><span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE jboss-app PUBLIC "-//JBoss//DTD Java EE Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd"> <jboss-app> <module-order>strict</module-order> </jboss-app></span></span>
全的pom内容
<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" 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>com.tgb</groupId> <artifactId>lishehetestear</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>ear</packaging> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_api</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_core</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </dependency> <dependency> <groupId>com.tgb</groupId> <artifactId>lishehe_war</artifactId> <version>0.0.1-SNAPSHOT</version> <type>war</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-ear-plugin</artifactId> <version>2.9</version> <configuration> <packagingIncludes>META-INF/**,**/lishehe_*.jar,**/lihehe_*.war</packagingIncludes> <jboss> <version>5</version> <module-order>strict</module-order> </jboss> <modules> <jarModule> <groupId>com.tgb</groupId> <artifactId>lishehe_api</artifactId> <includeInApplicationXml>true</includeInApplicationXml> </jarModule> <jarModule> <groupId>com.tgb</groupId> <artifactId>lishehe_core</artifactId> <includeInApplicationXml>true</includeInApplicationXml> </jarModule> <webModule> <groupId>com.tgb</groupId> <artifactId>lishehe_war</artifactId> </webModule> </modules> </configuration> </plugin> </plugins> </build> </project></span></span>
剩下的就是部署了,直接扔到Jboss里面即可,
总结
这个时候深刻体会到英语很重要啊,细心的深入的去学习,查资料(外网的靠谱)。
用Maven打包成EAR部署JBoss