Top Rounds
| We are Hiring! |

Adding jars to Sahi's classpath ·

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.

From command-line

If you are using start_sahi.bat or start_dashboard.bat, edit it 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

  • mysql-connector-java-5.0.4-bin.jar is the mysql jdbc driver which has been copied to sahi/extlib/db directory. custom.jar is in C:\mypath.
  • You can keep your jar anywhere and use its absolute path or a path relative to where you start Sahi from.
  • SAHI_EXT_CLASS_PATH is where you add your database drivers.
  • On linux use : (colon) instead of ; (semi-colon) to separate jars in the classpath

From ant

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.)




---


Top Rounds