Prerequisites
- Java
- XML
- Eclipse
- Batch scripting
Installing JBoss AS
- Download and install the Java 1.5 SDK or higher.
- Download the most recent stable binaries from http://www.jboss.org/jbossas/downloads/.
- Unzip the files to the directory of your choice.
- Create an environment variable called
JBOSS_HOMEthat points to the directory. The command is:export PATH=$PATH:(yourDir). - JBoss AS is ready to be used.
Starting JBoss AS
At the command prompt, go to theJBOSS_HOME/bin/ directory and run the run.sh (Linux/Mac/Unix) or run.bat (Windows). You will then see a load of logging information. The JBoss AS will be completely up and running when you see something like:
15:45:12,525 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 42s:254msat the command prompt. To verify that it is working properly, navigate in your favorite browser to
http://servername:8080/, where servername is the name of the host.
Shut Down JBoss AS
At the command prompt, go to theJBOSS_HOME/bin/ directory and run shutdown.sh (Linux/Mac/Unix) or shutdown.bat (Windows).
Point Eclipse to APIs
If Eclipse does not recognize the portlets, servlets, log4j (basically most J2EE APIs and frameworks) fresh out of the box, they will need to be included in the build paths.Portlets/Servlets/Logging APIs
- Download the following APIs (there are alot more, but this is all Ive used so far):
-
portlet-api-1.0.jar -
servlet-api.jar -
log4j-1.2.15.jar(or most recent)
-
- Open the Preferences dialog in Eclipse.
- Expand the tree labeled
Java. - Expand the sub-tree labeled
Build Path. - Click on
User Libraries. - Click
New. - Provide appropriate name for the library, such as
J2EE_Libs. - Select the newly created library and click on
Add JARs. - Locate the jars downloaded from above.
- Add each one to the library.
- Click
OK. - Right click on the project that requires the APIs, expand
Build Path, and click onConfigure Build Path. Alternatively, you may click on theProjectmenu and click on properties. - Click on
Java Build Pathfrom the menu. - Click on the
Librariestab. - Click on
Add Library. - Select
User Libraryfrom the list then click Next. - Checkmark the box next to the library that was just created and click
Finish. - Click
OK. - The project will have the libraries added.
Configuring Remote Debugging in Eclipse
JBoss AS Config:- Navigate to
JBOSS_HOME/bin. - Open the
run.conf(run.batfor windows) file for editing. - Add the following:
In run.conf:# Remote debugging for Eclipse
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787, server=y, suspend=n"after these lines:
#
In run.bat:
# Specify options to pass to the Java VM.
#
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
firem Enable remote debugging.
after these lines:
set JAVA_OPTS= -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y %JAVA_OPTS%rem With Sun JVMs reduce the RMI GCs to once per hour
set JAVA_OPTS=%JAVA_OPTS% -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 - Save the file.
- The JBoss AS is now configured for remote debugging.
*Note: JBoss AS will need to be restarted for changes to take effect.
Eclipse Config:
- Open the Preferences dialog in Eclipse.
- Expand the
Servertree and click onInstalled Runtimes. - Click on
Add. - Select the version of JBoss that is being used.
- Make sure
Also create new serveris checked. - Click
Next. - Select the JRE that JBoss will be running on.
- Specify the directory where the JBoss files reside.
- Click
Next. - Specify the IP of the server. If running locally, use 127.0.0.1.
- If you decided to change the port number for JBoss, be sure to change it here to match.
- Use the defaults for the rest of the fields.
- Click
Finish. - Eclipse is now setup for remote debugging.
Configuring Startup Timeout
When starting from Eclipse, JBoss takes a little longer to boot. Eclipse will prevent it from starting completely if it takes too long (ie more than 50 seconds). It typically starts for me in 1 min 20 secs. To change the settings, follow these instructions:- Open Eclipse.
- Go to Preferences.
- Click on
Server. - Change the option labled
Server timeout delay:toUnlimited. - Click
OK.
Configuring PermGen
Periodically when developing and redeploying web apps, an error will occur and the JBoss AS will crash, burn, and will require a restart. Most of the time, the error is an out of memory error and will appear in the console as follows:10:10:22,640 ERROR [MainDeployer] Could not create deployment: file:(yourFile)To fix this you will need to modify the run file, again. There are two options: increase the size of the PermGen or allow garbage collection on PermGen . Each method has its pro/cons. Increasing the size of the PermGen will only delay the errors longer, because the memory will be used up eventually. If all you are looking to do is increase the time between restarts, this is a viable solution. If low memory is an issue or if the error must be prevented altogether, then garbage collection should be permitted on PermGen. With this solution, you may run the risk of garbage collecting classes that will be used again (this has not been tested). Both may be used which may lessen the risk that classes will be collected before their time. Realize that this does not eliminate the risk. Note that both methods will require JBoss AS to be restarted.
java.lang.OutOfMemoryError: PermGen space
Increase Memory Size of PermGen:
- Navigate to
JBOSS_HOME/bin/. - Open the
run.conf(run.batfor windows) file for editing. - Add the following after the remote debugging lines:
In run.conf:# Memory configuration to delay PermGen: OutOfMemoryError(s)
In run.bat:
JAVA_OPTS="$JAVA_OPTS -XX:MaxPermSize=512m"rem Memory configuration to delay PermGen: OutOfMemoryError(s)
set JAVA_OPTS=-XX:MaxPermSize=512m %JAVA_OPTS% - Save the file.
- PermGen will be configured with a larger memory space.
Garbage Collection on PermGen
- Navigate to
JBOSS_HOME/bin/. - Open the
run.conf(run.batfor windows) file for editing. - Add the following after the remote debugging lines:
In run.conf:# Garbage Collection configuration to fix PermGen: OutOfMemoryError(s)
In run.bat:
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled"rem Garbage Collection configuration to fix PermGen: OutOfMemoryError(s)
set JAVA_OPTS= -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled %JAVA_OPTS% - Save the file.
- PermGen will be configured to be garbage collected.
Application/Server Specific Configurations
Directories
As of JBoss 4.0.0, there are 3 folders/configurations that are supported:-
default -
minimal -
standard
Each folder supports a different JBoss "configuration." The minimal will load the bare essentials for JBoss to run. The default is what is used when run.sh/run.bat is executed. It loads the most commonly used components in JBoss. This is the directory that will be used most often. Other configurations may be created. Just create your own folder, copy an existing config into it, and then modify it to your needs. To launch something other than default, use run.sh -c configuration, where configuration is the folder name. Replace run.sh with run.bat for Windows.
There are 4 directories in JBOSS_HOME/server/(yourConfigDir) that are of most concern in a J2EE App:
-
/conf -
/deploy -
/lib -
/log
The /conf folder contains configuration files for the server. The /deploy folder is where .ear, .war, services, and data sources are stored. This folder is hot deployable, meaning anything placed here will automatically be detected by the AS. The /lib folder contains any necessary libraries/jar files for an application (such as the JDBC drivers). The /log folder contains all the logs for the JBoss configuration. The boot log, server logs, and application logs will be found here. Depending on the size of the hard drive, these logs will have to be periodically deleted. JBoss generates a massive amount of logs and will take up alot of space. These 4 folders will be in JBOSS_HOME/server/(yourConfigDir).
Configuring Hot Deploy
The JBoss AS automatically deploys .war, .ear, etc when they are dropped into the deploy directory. However, it may sometimes take up to a minute for JBoss to recognize that there was a change. For changes to occur almost instantaneously follow these instructions:- Navigate to
JBOSS_HOME/server/(yourConfigDir)/conf - Open
jboss-service.xmlfor editing. - Find the tags:
<attribute name="ScanPeriod"></attribute>
- The value should be something like
5000. Change this to500. - Save the file.
*Note: If the change does not take effect, look for a file named
jboss-yourConfigDir.xml and follow the rest of the directions.This is ideal for a development server, however, with each hot deploy errors may occur. An example would be the state of a session if a user was connected. Additionally, JBoss seems to deteriorate after many hot deploys. You'll have to periodically restart the app server to fix this. This is not something that is recommended for a production environment. If one wishes to disable hot deploy, all they have to do is change the tags
<attribute name="ScanEnabled">true</attribute>
injboss-service.xml to false. Running JBoss as a Service
I recently came across a phenomenon on one of our production environments where JBoss would shutdown every night. I would start the server using bin/run.sh -b 0.0.0.0 from a remote login and every time it would shutdown 30 minutes to 45 minutes after I left work. I ascertained it was due to the remote session closing which also closes all child processes. There are two solutions:- Run using the nohop argument
- Start JBoss as a daemon/service






Comments
Write New Comment ▼
Write New Comment
Sorry! This knol's owner(s) have blocked you from editing, making suggestions, or commenting here.