Dynamic loading of JACL
procedures/modules into JACL scripts.
It's now possible to dynamically load jacl procedures(modules) into a
top
level script without explicitly specifying procedure locations using
the source command. The JACL auto_path variable holds a list of
directories that JACL will search for procedures or namespaces that are
called by a top level script. If JACL cannot resolve the location
of a called procedure locally it searches the list of directories held
in the auto_path variable for a tclIndex file that contains load
instructions for the procedures in the directory. The tclIndex
file is generated by the auto_mkindex command and this command must be
run each time procedures names are changed and procedures are added or
deleted. The auto_path variable is initialized by the TCLLIBPATH
environmental variable or explicitly within the script.
Example 1 - Dynamic Loading of procedures
from a flat file directory .
The flat file directory is located at
C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib.
The procedures must be clean i.e have no syntax errors or auto_mkindex
will error out. Use the nagelfar
syntax checker to scan the directory. Nagelfar
requires Tcl/Tk so download the free Active State distro
from Active
State if required.
Run the auto_mkindex command.
C:\>tclsh
% auto_mkindex
C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin\\WAS6.1\\JACL\\proclib
*.tcl
Open the tclIndex file in
C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin\\WAS6.1\\JACL\\proclib
You should see the index entries.
set auto_index(::getJVMInfoNew::getJVMInfoNew) [list source [file join
$dir getJVMinfoNew_proc.tcl]]
set auto_index(glob-r) [list source [file join $dir glob-r_proc.tcl]]
set auto_index(hashMapList) [list source [file join $dir
hashMapList_proc.tcl]]
set auto_index(hashMap) [list source [file join $dir hashMap_proc.tcl]]
set auto_index(::installApp2::installApp) [list source [file join $dir
installApp2_proc.tcl]]
set auto_index(::installApp2::setAppProperties) [list source [file join
$dir installApp2_proc.tcl]]
set auto_index(::installApp2::getRoleMappings) [list source [file join
$dir installApp2_proc.tcl]]
set auto_index(::installApp2::displayModList) [list source [file join
$dir installApp2_proc.tcl]]
Initialise the auto_path variable.
The auto_path variable needs to be populated with the proclib directory
location. In JACL the default auto_path is set to
resource:/tcl/lang/library
wsadmin>set auto_path
resource:/tcl/lang/library
On startup JACL looks for the TCLLIBPATH environment parameter and
populates the auto_path variable with it's contents. Use the
wsadmin -javaoption flag to set the TCLLIBPATH parameter.
Run WsAdmin using -javaoption
flag with TCLLIBPATH.
@echo
off
setlocal
set
wsadminDir=C:\IBM\WASND61\AppServer\bin
set
TCLLIBPATH="TCLLIBPATH=C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin/WAS6.1\\JACL\\proclib"
set host="yourHost"
set port="8879"
set user="yourUserid"
set password="yourPassword"
call %wsadminDir%\wsadmin.bat -user
%user% -password %password% -lang jacl -javaoption -D%TCLLIBPATH% -host
%host% -port %port%
endlocal
Now check the
auto_path.
wsadmin>set auto_path
resource:/tcl/lang/library {C:\home\patrick\eclipse\WASAdminSBV\WSAdmin/WAS6.1\JACL\proclib}
Dynamically load the "putsLog" command.
wsadmin>putsLog "test message"
[yourHost]:[2007-08-21-08.28.26] test message
Example 2 - Dynamic Loading of procedures
from
a jar file.
JACL can search jar files for procedures/modules if the jar file is
defined as a resource on the auto_path AND the jar file is on the
classpath.
The target directory is located at
C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib.
The procedures must be clean i.e have no syntax errors or auto_mkindex
will error out. Use the nagelfar
syntax checker to scan the directory. Nagelfar
requires Tcl/Tk so download the free Active State distro
from Active
State if required.
Run the auto_mkindex command.
C:\>tclsh
% auto_mkindex
C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin\\WAS6.1\\JACL\\proclib
*.tcl
Open the tclIndex file in
C:\\home\\patrick\\eclipse\\WASAdminSBV\\WSAdmin\\WAS6.1\\JACL\\proclib
You should see the index entries.
set auto_index(::getJVMInfoNew::getJVMInfoNew) [list source [file join
$dir getJVMinfoNew_proc.tcl]]
set auto_index(glob-r) [list source [file join $dir glob-r_proc.tcl]]
set auto_index(hashMapList) [list source [file join $dir
hashMapList_proc.tcl]]
set auto_index(hashMap) [list source [file join $dir hashMap_proc.tcl]]
set auto_index(::installApp2::installApp) [list source [file join $dir
installApp2_proc.tcl]]
set auto_index(::installApp2::setAppProperties) [list source [file join
$dir installApp2_proc.tcl]]
set auto_index(::installApp2::getRoleMappings) [list source [file join
$dir installApp2_proc.tcl]]
set auto_index(::installApp2::displayModList) [list source [file join
$dir installApp2_proc.tcl]]
Jar up the directory.
Use the java jar utility to jar up the proclib directory.
C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL>jar -cvf
proclib.jar proclib
Initialise the auto_path variable.
The auto_path variable defaults to /tcl/lang/library.
wsadmin>set auto_path
resource:/tcl/lang/library
On startup JACL looks for the TCLLIBPATH environment parameter and
populates the auto_path variable with it's contents. Use the
wsadmin
-javaoption flag to set the TCLLIBPATH parameter and the
-wsadmin_classpath flag to set the classpath.
@echo off
setlocal
set wsadminDir=C:\IBM\WASND61\AppServer\bin
set TCLLIBPATH="TCLLIBPATH=resource:/proclib"
set
WSCLASSPATH=%CLASSPATH%;C:\home\patrick\eclipse\WASAdminSBV\WSAdmin\WAS6.1\JACL\proclib.jar
set host="ws038223"
set port="8879"
set user="yourUserid"
set password="yourPassword"
call %wsadminDir%\wsadmin.bat -user %user% -password %password% -lang
jacl -javaoption -D%TCLLIBPATH%
-host %host% -port %port% -wsadmin_classpath
%WSCLASSPATH%
endlocal
Now check the auto_path.
wsadmin>set auto_path
resource:/tcl/lang/library resource:/proclib
Dynamically load the putsLog command.
wsadmin>putsLog "test message"
[yourHost] :[2007-08-21-08.19.21] test message