runwithtrace command script for Windows

To trace MQ Explorer, close and restart the MQ Explorer by using the runwithtrace command script. A copy of this script for use on Windows systems is embedded in this topic.

Copy and save the following script as a text file called runwithtrace.cmd, then run the script as described in step 3 of "Using IBM MQ Explorer trace in other Eclipse environments".

@echo off

REM ---------------------------------------------------------------------------
REM File Name : runwithtrace.cmd
REM
REM File Description : This script is used when MQ Explorer plug-ins are 
REM installed into another Eclipse or Eclipse based product. 
REM It launches eclipse and will run WebSphere MQ Explorer with trace enabled.
REM 
REM ---------------------------------------------------------------------------

setlocal

REM ---------------------------------------------------------------------------
REM Special case for when MQ Explorer plug-ins are installed in an Eclipse or an
REM Eclipse based product.
REM
REM eclipse needs to be in current directory. 
REM ---------------------------------------------------------------------------

if exist "eclipse.exe" goto :MQExplorer_found
goto :no_MQExplorer

:MQExplorer_found
set explorerCmd=eclipse.exe

REM ---------------------------------------------------------------------------
REM Special processing for enabling trace
REM  1.  Allow a user to supply their own properties file, pointed to by the 
REM        MQPROPERTIES environment variable
REM  2. Otherwise, build a properties file in %temp% which writes trace
REM        to the MQ_INSTALLATION_PATH\trace directory if writeable, otherwise to
REM        %temp% itself
REM ---------------------------------------------------------------------------

if not "%MQPROPERTIES%."=="." goto :own_properties

REM Create a properties file with the default trace options
set MQPROPERTIES=%temp%\mq_trace.properties

REM Set MQTRACE to temp or the MQ trace directory
if "%MQ_JAVA_DATA_PATH%."=="." goto :set_to_temp

set MQTRACE=%MQ_JAVA_DATA_PATH%\trace
goto :finish_set
   
:set_to_temp
set MQTRACE=%temp%

:finish_set

REM -------------------------------------------------------------------
REM Where should trace be written to - Try the MQ trace directory first
REM -------------------------------------------------------------------
if "%MQTRACE%"=="%MQ_JAVA_DATA_PATH%\trace" goto :MQ_dir_available
echo Trace will be written to the temporary directory %MQTRACE%
goto :finish_trace_location

:MQ_dir_available
echo Confirming write access to the MQ trace directory %MQTRACE%
echo Test >> "%MQTRACE%\test.gui" 2>NUL
if exist "%MQTRACE%\test.gui" goto :MQ_dir_used
echo Trace will be written to the temporary directory %temp%
set MQTRACE=%temp%
goto :finish_trace_location

:MQ_dir_used
echo Trace will be written to the MQ trace directory %MQTRACE%
del "%MQTRACE%\test.gui" >nul 2>&1

:finish_trace_location

REM Convert back slashes to forward slashes for use in properties file 
REM Note :\=/ converts back slashes to forward slashes.
set MQTRACE=%MQTRACE:\=/%


REM -------------------------------------------------------------
REM Now build the default properties file
REM -------------------------------------------------------------
echo Diagnostics.MQ=enabled > %MQPROPERTIES%
echo Diagnostics.Java=all >> %MQPROPERTIES%
echo Diagnostics.Java.Trace.Detail=high >> %MQPROPERTIES%
echo Diagnostics.Java.Trace.Destination.File=enabled >> %MQPROPERTIES%
echo Diagnostics.Java.Trace.Destination.Console=disabled >> %MQPROPERTIES%
echo Diagnostics.Java.Trace.Destination.Pathname=%MQTRACE% >> %MQPROPERTIES%
echo Diagnostics.Java.FFDC.Destination.Pathname=%MQTRACE% >> %MQPROPERTIES%
echo Diagnostics.Java.Errors.Destination.Filename=%MQTRACE% >> %MQPROPERTIES%


:own_properties

REM ---------------------------------------------------------------------------
REM Build the command line
REM All parameters passed to this script are passed through.
REM Set the load time weaving options, it's set as part of the vmargs parameter.
REM ---------------------------------------------------------------------------

REM Note.
REM In eclipse and eclipse based products the osgi.framework.extensions is set
REM as part of the Equinox Weaving plug-ins eclipse installation.
REM Therefore unlike in the normal MQ Explorer script LTW_OPTIONS is empty

REM set LTW_OPTIONS=-Dosgi.framework.extensions=org.eclipse.equinox.weaving.hook 
set LTW_OPTIONS=
set explorerCmd=%explorerCmd% %* -vmargs -Xmx512M %LTW_OPTIONS% "-Dcom.ibm.mq.commonservices=%MQPROPERTIES%"


REM ---------------------------------------------------------------------------
REM Launch MQ Explorer
REM ---------------------------------------------------------------------------
echo Launching %explorerCmd%
start %explorerCmd%

goto :end

:no_MQExplorer
echo ERROR - eclipse.exe not found in the current directory.
echo ERROR - This script needs to be run in the same directory as eclipse.exe

:end
endlocal