While interacting with databases or while calling custom java code from Sahi scripts, the necessary classes or jars need to be added to Sahi’s classpath.
If you are using start_sahi.bat, edit start_sahi.bat and modify
SET SAHI_EXT_CLASS_PATH=
to
SET SAHI_EXT_CLASS_PATH=path/to/your/jar
Example:
SET SAHI_EXT_CLASS_PATH=..\..\extlib\db\mysql-connector-java-5.0.4-bin.jar;
SET SAHI_EXT_CLASS_PATH=%SAHI_EXT_CLASS_PATH%;C:\mypath\custom.jar
In the above example, we are adding 2 jars to the classpath. Note the following
SAHI_EXT_CLASS_PATH is where you add your database drivers.If you are using ant, use:
<target name="startsahi" description="starts proxy">
<java classname="net.sf.sahi.Proxy" fork="true">
<classpath>
<path path="classes"/>
<pathelement location="extlib/rhino/js.jar"/>
<pathelement location="extlib/apc/commons-codec-1.3.jar"/>
<pathelement location="extlib/db/mysql-connector-java-5.0.4-bin.jar"/>
<pathelement location="C:/mypath/custom.jar"/>
</classpath>
<arg value="." id="basePath"/>
<arg value="./userdata/" id="userdataPath"/>
</java>
</target>
Make sure to change the pathelement locations properly. (Relative to where you are running the target from.)