Thread: [tcljava-user] "source resource:/" - howto?
Brought to you by:
mdejong
From: Patrick F. <fin...@gm...> - 2007-07-16 09:57:19
|
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. Thanks. Patrick. |
From: Mo D. <mo...@mo...> - 2007-07-16 19:16:54
|
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 |
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 |
From: Mo D. <mo...@mo...> - 2007-07-17 19:13:17
|
Patrick Finnegan wrote: > > > 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 Package require is supported under Jacl. It is likely you are not using the auto_path variable in the way it should, you can add a path with a "resource:/" prefix to the auto_path and it should be searched as expected. > 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%" > This is not how TCL_LIBRARY should be used. In general, TCL_LIBRARY is where Tcl/Jacl find its own scripts. You should not use this for your application scripts. cheers Mo DeJong |
From: Tom P. <tpo...@ny...> - 2007-07-17 21:21:56
|
On Tue, Jul 17, 2007 at 12:11:37PM -0700, Mo DeJong wrote: > Patrick Finnegan wrote: > > 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 > Package require is supported under Jacl. It is likely you are not using > the auto_path variable in the way it should, you can add > a path with a "resource:/" prefix to the auto_path and it should be > searched as expected. > > > 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%" > > > This is not how TCL_LIBRARY should be used. In general, TCL_LIBRARY is > where Tcl/Jacl > find its own scripts. You should not use this for your application scripts. Jacl uses TCLLIBPATH, not TCL_LIBRARY to find packages. Jacl's init.tcl holds all of the clues: http://tcljava.cvs.sourceforge.net/tcljava/tcljava/src/jacl/tcl/lang/library/init.tcl?revision=1.7&view=markup I routinely use a modified 'jaclsh' that allows me to include Tcl packages that I place either in my Jacl installation dir (ones that are Jacl only), or specify other directories via an environment variable. For example: $ export JACL_LIBRARY=/usr/lib/tcllib1.7 $ jaclsh % # include my jacl based 'hyde' package % package require hyde 1.3 % # include log from tcllib % package require log 1.2 TCLLIBPATH is not split on ":", you have to space-separate directory entries. My Jacl installation : ls -CF /usr/local/lib/tcljava1.4.0 hyde-1.3/ itclsrc.jar jaclsrc.jar janinosrc.jar tcljava.jar tjc.jar itcl.jar jacl.jar janino.jar swank.jar tcljavasrc.jar tjcsrc.jar The hyde-1.3 directory has a valid pkgIndex.tcl file: package ifneeded hyde 1.3 "source [file join $dir hyde.tcl]" Note Tcllib1.7 has very few packages that require Tcl 8.0, I just used that as an example. Tcllib was installed from my Linux package system. Here is my 'jaclsh', a couple of notes first. - I copy swank.jar into my Jacl installation, and do 'ln -s jaclsh wisk'. That way, I can start Jacl or Swank from the same script, either by invoking 'jaclsh' or 'wisk'. - The following environment variables are recognized: JACL_FLAGS - JVM memory & other options JACL_LIBRARY - Tcl libraries to include JACL_PROPS - other JVM options, I use this for any "-Dxxxx=yyy" JACL_MAIN - if using a custom shell JAVA_HOME - which ever JVM I want to use --------------------------------------------------------------------- #!/bin/sh # Install prefix for jacl package, defaults to /usr/local prefix=/usr/local # Tcl/Java version number TCLJAVA_VERSION=1.4.0 # Directory where Jacl installation .jar files exists, and # other Jacl packages XP_TCLJAVA_INSTALL_DIR=${prefix}/lib/tcljava${TCLJAVA_VERSION} JACL_CLASSPATH=${XP_TCLJAVA_INSTALL_DIR}/tcljava.jar JACL_CLASSPATH=${JACL_CLASSPATH}:${XP_TCLJAVA_INSTALL_DIR}/jacl.jar JACL_CLASSPATH=${JACL_CLASSPATH}:${XP_TCLJAVA_INSTALL_DIR}/itcl.jar JACL_CLASSPATH=${JACL_CLASSPATH}:${XP_TCLJAVA_INSTALL_DIR}/tjc.jar JACL_CLASSPATH=${JACL_CLASSPATH}:${XP_TCLJAVA_INSTALL_DIR}/janino.jar # Fully qualified path name of JVM executable # Will be overridden if $JAVA_HOME is set and $JAVA_HOME/bin/java exists JAVA=/usr/local/java/bin/java # The arguments to the JAVA command DEFAULT_JACL_FLAGS="-ms5m -mx32m" JACL_FLAGS="${JACL_FLAGS:-$DEFAULT_JACL_FLAGS}" # If JACL_MAIN is set then use it as the name of the Java # class to execute. If it is not set, then use tcl.lang.Shell. # This provides an easy way to launch an alternative shell # without having to duplicate all the CLASSPATH and JAVA logic. if test "${JACL_MAIN}" = ""; then if [ `basename $0` = "wisk" ] ; then JACL_MAIN=tcl.lang.SwkShell JACL_CLASSPATH=${JACL_CLASSPATH}:${XP_TCLJAVA_INSTALL_DIR}/swank.jar else JACL_MAIN=tcl.lang.Shell fi fi # set CLASSPATH CLASSPATH=${JACL_CLASSPATH}:${CLASSPATH} export CLASSPATH # Fully qualified path name of JVM executable if [ -n "$JAVA_HOME" -a -x $JAVA_HOME/bin/java ] ; then JAVA=$JAVA_HOME/bin/java fi # Set TCLLIBPATH from JACL_LIBRARY and default JACL_LIBPATH="-DTCLLIBPATH=$JACL_LIBRARY $XP_TCLJAVA_INSTALL_DIR" exec ${JAVA} ${JAVA_FLAGS} "${JACL_LIBPATH}" ${JACL_PROPS} ${JACL_MAIN} ${1+"$@"} --------------------------------------------------------------------- -- Tom Poindexter tpo...@ny... |