Re: [tcljava-user] "source resource:/" - howto?
Brought to you by:
mdejong
From: Patrick F. <fin...@gm...> - 2007-07-17 07:10:44
|
On 16/07/07, Mo DeJong <mo...@mo...> wrote: > > Patrick Finnegan wrote: > > > > Can someone post an example or point to an example of how to use > > "source resource:/". I want to put my JACL scripts in a jar file and > > put the jar file on the class path. > > > The most simple example would go like so: > > % source resource:/tcl/lang/library/parray.tcl > > This uses the Java API to load a resource named > "/tcl/lang/library/parray.tcl" > > This is loaded from jacl.jar via the system classloader: > > $ jar -tvf jacl.jar | grep parray > 885 Thu Apr 19 13:34:28 PDT 2007 tcl/lang/library/parray.tcl > > To add your own scripts that use source, just jar up your .tcl files and > place the jar on the CLASSPATH. > > Mo DeJong The way I normally load the procedure library is; 1. Set a java system variable using the D option. export TCL_LIBRARY="TCL_LIBRARY=/directoryPath/JACL java bla bla bla -D$TCL_LIBRARY 2. Pick up the TCL_LIBRARY variable in the top level jacl script. set TCL_LIBRARY [ java::call System getProperty TCL_LIBRARY ] 3. Call a "sourceProcs.tcl script. source [ file join $TCL_LIBRARY sourceProcs.tcl ] Every top level script gets the $TCL_LIBRARY variable and calls sourceProcs.tcl which does a recursive search under the TCL_LIBRARY directory, locates any directory called proclib and sources each procedure script in the proclib directory loading everything up into the namespace. What I would really like to do is dynamically load the procedure scripts as required in a "package require" type scenario. But "package require" is not supported under jacl so I thought about using auto_mkindex which seems to be supported under jacl. It seems to work with both directories and jar files. Great! 1. Directory. ******* wsadmin>auto_mkindex proclib then ................... set TCL_LIBRARY="directoryPath/proclib" Call jacl with the java -D option java bla bla bla "-DTCL_LIBRARY=%TCL_LIBRARY%" Within the script...... set TCL_LIBRARY [ java::call System getProperty TCL_LIBRARY ] lappend auto_path $TCL_LIBRARY Now procedures are loaded dynamically without the need for an explicit source command. javaMail::javaMail xxxxx xxxxx xxxxx 2. Jar File. ****** wsadmin>auto_mkindex proclib jar -cvf proclib set CLASSPATH=%CLASSPATH%;directorypath/proclib.jar java bla bla bla -classpath %CLASSPATH% lappend auto_path resource:/proclib javaMail::javaMail xxxxx xxxxx xxxxx |