After a third-party package is referenced in the EJB, the package must be configured in JBoss or the project will fail to deploy.
In previous versions of JBOSS7, these third packages could be placed under%jboss_home%/common/lib, but JBOSS 7 was completely different from the previous version. JBoss 7 uses module loading, third-party jar packages are also loaded as modules, so third-party jar packages need to be configured in JBoss 7.
The configuration is divided into two steps, one is in modules this folder with the package hierarchy as the folder name, the last level is the version number, not the main, such as the example:
package calculate;publicclass Calculate { publicintadd(int a,int b){ return a+b; } publicintminus(int a,int b){ return a-b; }}
This is a simple calculate class, the owning package is calculate, only one level, so the hierarchy in the Modules folder is as follows:
For example, we need three more files: a jar package that needs to be used, one is prefixed with the jar package name, the. Index is the suffix of the file, and the last is the Module.xml file
The contents of Calculate.jar.index are as follows:
META-INFcalculate
It contains the package name to be required.
The contents of the Module.xml file are as follows:
<?Xmlversion="1.0"encoding="UTF-8"?><!--~ JBoss, Home ofProfessional Open Source. ~ Copyright ., Red Hat, Inc., andIndividual Contributors ~ asIndicated by the@author tags. See theCopyright.txtfile inch the~ Distribution for aFull Listing ofIndividual contributors. ~ ~ This is the free software; You can redistributeit and/orModifyit~ under theTerms of theGNU Lesser general public License as~ Published by theFree software Foundation; Eitherversion 2.1 of~ theLicense,or( atYour option) anyLaterversion. ~ ~ This software is distributedinch theHope thatitwould be useful, ~ but without any WARRANTY;withoutEven theImplied warranty of~ merchantabilityorFITNESS for A particular PURPOSE. See theGNU ~ Lesser general public License forMore details. ~ ~ You should has receivedaCopy of theGNU Lesser general public ~ License along withThis software;if not,Write to theFree ~ Software Foundation, Inc.,WuyiFranklin St, Fifth Floor, Boston, MA ~02110-1301USA,orSee theFSF site:http://www.fsf.org. -<module xmlns="urn:jboss:module:1.0"Name="Calculate"> <resources> <resource-root path="Calculate.jar"/> <!--Insert resources here--</resources> <dependencies> </dependencies></module>
The emphasis is on the following Name property and the Resources child node and dependecies, which place the jar package file name, which places the dependency of this jar package.
Once the above several files are ready, go to the Standalone\configuration folder and open the Standalone.xml
Find (113 rows or so), add code to this node,
The final node content is as follows:
<subsystem xmlns="urn:jboss:domain:ee:1.0"> <global-modules> <module name="calculate" slot="main"/> </global-modules> </subsystem>
Once you're done, restart the server to deploy the EJB again.
"Developing Java EE 6" EJB referencing third-party packages using JBoss 7