Este contenido no está disponible en el idioma seleccionado.
7.4. Create a Custom Module
The following procedure describes how to create a custom module in order to make properties files and other resources available to all applications running on the JBoss EAP server.
Procedure 7.2. Create a Custom Module
- Create and populate the
module/directory structure.- Create a directory structure under the
EAP_HOME/moduledirectory to contain the files and JARs. For example:cd EAP_HOME/modules/ mkdir -p myorg-conf/main/properties
$ cd EAP_HOME/modules/ $ mkdir -p myorg-conf/main/propertiesCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Move the properties files to the
EAP_HOME/modules/myorg-conf/main/properties/directory you created in the previous step. - Create a
module.xmlfile in theEAP_HOME/modules/myorg-conf/main/directory containing the following XML:<module xmlns="urn:jboss:module:1.1" name="myorg-conf"> <resources> <resource-root path="properties"/> </resources> </module><module xmlns="urn:jboss:module:1.1" name="myorg-conf"> <resources> <resource-root path="properties"/> </resources> </module>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Modify the
eesubsystem in the server configuration file. You can use the Managemet CLI or you can manually edit the file.- Follow these steps to modify the server configuration file using the Management CLI.
- Start the server and connect to the Management CLI.
- For Linux, enter the following at the command line:
EAP_HOME/bin/jboss-cli.sh --connect
EAP_HOME/bin/jboss-cli.sh --connectCopy to Clipboard Copied! Toggle word wrap Toggle overflow - For Windows, enter the following at a command line:
C:\>EAP_HOME\bin\jboss-cli.bat --connect
C:\>EAP_HOME\bin\jboss-cli.bat --connectCopy to Clipboard Copied! Toggle word wrap Toggle overflow
You should see the following response:Connected to standalone controller at localhost:9999
Connected to standalone controller at localhost:9999Copy to Clipboard Copied! Toggle word wrap Toggle overflow - To create the
myorg-conf<global-modules> element in theeesubsystem, type the following in the command line:/subsystem=ee:write-attribute(name=global-modules, value=[{"name"=>"myorg-conf","slot"=>"main"}])/subsystem=ee:write-attribute(name=global-modules, value=[{"name"=>"myorg-conf","slot"=>"main"}])Copy to Clipboard Copied! Toggle word wrap Toggle overflow You should see the following result:{"outcome" => "success"}{"outcome" => "success"}Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Follow these steps if you prefer to manually edit the server configuration file.
- Stop the server and open the server configuration file in a text editor. If you are running a standalone server, this is the
EAP_HOME/standalone/configuration/standalone.xmlfile, or theEAP_HOME/domain/configuration/domain.xmlfile if you are running a managed domain. - Find the
eesubsystem and add the global module formyorg-conf. The following is an example of theeesubsystem element, modified to include themyorg-confelement:Example 7.3.
myorg-confelement<subsystem xmlns="urn:jboss:domain:ee:1.0" > <global-modules> <module name="myorg-conf" slot="main" /> </global-modules> </subsystem><subsystem xmlns="urn:jboss:domain:ee:1.0" > <global-modules> <module name="myorg-conf" slot="main" /> </global-modules> </subsystem>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
- Assuming you copied a file named
my.propertiesinto the correct module location, you are now able to load properties files using code similar to the following:Example 7.4. Load properties file
Thread.currentThread().getContextClassLoader().getResource("my.properties");Thread.currentThread().getContextClassLoader().getResource("my.properties");Copy to Clipboard Copied! Toggle word wrap Toggle overflow