Monday, June 29, 2015

Connecting jvisualvm to JBoss EAP 6.2 on Windows

In case you want to use jvisualvm to connect up to JBoss EAP 6.2 on Windows, you can use the following script (which should be placed into JBOSS_HOME/bin as jvisualvm.bat):
@echo off  
rem -------------------------------------------------------------------------  
rem jvisualvm script for Windows  
rem -------------------------------------------------------------------------  
rem  
rem A script for running jvisualvm with the remoting-jmx libraries on the classpath.  
  
rem $Id$  
  
@if not "%ECHO%" == ""  echo %ECHO%  
@if "%OS%" == "Windows_NT" setlocal  
  
if "x%JAVA_HOME%" =="x" (  
    echo JAVA_HOME environment variable has not been set - please set and re-run!  
    goto :EOF  
)  
  
if "%OS%" == "Windows_NT" (  
  set "DIRNAME=%~dp0%"  
) else (  
  set DIRNAME=.\  
)  
  
pushd %DIRNAME%..  
set "RESOLVED_JBOSS_HOME=%CD%"  
popd  
  
if "x%JBOSS_HOME%" == "x" (  
  set "JBOSS_HOME=%RESOLVED_JBOSS_HOME%"  
)  
  
pushd "%JBOSS_HOME%"  
set "SANITIZED_JBOSS_HOME=%CD%"  
popd  
  
if "%RESOLVED_JBOSS_HOME%" NEQ "%SANITIZED_JBOSS_HOME%" (  
    echo WARNING JBOSS_HOME may be pointing to a different installation - unpredictable results may occur.  
)  
  
set DIRNAME=  
  
if "%OS%" == "Windows_NT" (  
  set "PROGNAME=%~nx0%"  
) else (  
  set "PROGNAME=jdr.bat"  
)  
  
rem Setup JBoss specific properties  
if "x%JAVA_HOME%" == "x" (  
  echo JAVA_HOME is not set. Unable to locate the jars needed to run jconsole.  
  goto END  
)  
  
rem Find jboss-modules.jar, or we can't continue  
if exist "%JBOSS_HOME%\jboss-modules.jar" (  
    set "RUNJAR=%JBOSS_HOME%\jboss-modules.jar"  
) else (  
  echo Could not locate "%JBOSS_HOME%\jboss-modules.jar".  
  echo Please check that you are in the bin directory when running this script.  
  goto END  
)  
  
rem Setup The Classpath  
set CLASSPATH=%JBOSS_HOME%\bin\client\jboss-cli-client.jar  
  
  
"%JAVA_HOME%\bin\jvisualvm.exe" "-cp:a" "%CLASSPATH%"  
  
:END  
goto :EOF  
:EOF 

Now inside jvisualvm you can connect to JBoss EAP 6 using JMX and a URL of the form service:jmx:remoting-jmx://<host>:<native-management-port>

See also "How to connect to JBoss EAP 6 using JConsole" (https://access.redhat.com/solutions/149973)