用Maven打包成EAR部署JBoss
來源:程序員人生 發布時間:2015-01-07 08:08:27 閱讀次數:4324次
基于原理的架構里面,斟酌這次升級版本,可謂是1步1個腳印的向上走啊,可以說步步為坎,他人的知識,和自己的知識,相差很多啊,甚么都懂點,但是具體沒有使用,就理解不深入了,愛莫能助,所以1切我們自己來操作吧,可謂是體會深入了,各種錯,各種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層
我要把這3個包打成1個eao包,把相互的依賴關系打到1起,參考官網
新建1個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⑷.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文件報錯,那末安裝1下 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依照字母加載,需要改成依照1定的依賴關系加載
只是在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⑻"?>
<!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⑻"?>
<!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⑷.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里面便可,
總結
這個時候深入體會到英語很重要啊,仔細的深入的去學習,查資料(外網的靠譜)。
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈