<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <!-- Created by texi2html 1.76 --> <!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others. Maintained by: Many creative people <dev@texi2html.cvshome.org> Send bugs and suggestions to <users@texi2html.cvshome.org> --> <head> <title>Crystal Space 1.2.1: 4.18.2 Java Bindings</title> <meta name="description" content="Crystal Space 1.2.1: 4.18.2 Java Bindings"> <meta name="keywords" content="Crystal Space 1.2.1: 4.18.2 Java Bindings"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="texi2html 1.76"> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} pre.display {font-family: serif} pre.format {font-family: serif} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: serif; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: serif; font-size: smaller} pre.smalllisp {font-size: smaller} span.sansserif {font-family:sans-serif; font-weight:normal;} ul.toc {list-style: none} --> </style> </head> <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> <a name="Java-Bindings"></a> <a name="0"></a> <table cellpadding="1" cellspacing="1" border="0"> <tr><td valign="middle" align="left">[<a href="iScript-Interface.html#0" title="Previous section in reading order"> < </a>]</td> <td valign="middle" align="left">[<a href="Perl-Bindings.html#0" title="Next section in reading order"> > </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> << </a>]</td> <td valign="middle" align="left">[<a href="Scripting-Languages.html#0" title="Up section"> Up </a>]</td> <td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> >> </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td> <td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td> <td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td> <td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td> </tr></table> <hr size="1"> <h3 class="subsection"> 4.18.2 Java Bindings </h3> <p><em>Written by Eric Sunshine, <a href="mailto:sunshine@sunshineco.com">sunshine@sunshineco.com</a></em>. </p> <p>The csJava module provides access to Crystal Space from Java in the form of a set of classes in the package <samp>‘org.crystalspace3d’</samp> which can be imported into pure Java programs. The csJava module consists of a <small>JAR</small> package, <tt>‘crystalspace.jar’</tt>, and a shared library, <tt>‘csjava’</tt>. </p> <p>The Crystal Space classes, interfaces, and methods exported to Java are used in almost the same fashion as in C++. Consequently, the Crystal Space Public <small>API</small> Reference can be consulted in most cases. There is also a sample program which shows concretely how to utilize Crystal Space from Java. It performs the same functionality as the first C++ tutorial (see section <a href="Tutorial-Simple.html#0">Simple Tutorial 1: Basic Setup, World Creation</a>). </p> <p>Presently, the caJava module can be built only by people using Jam or “make” to build Crystal Space. To build csJava, follow these instructions: </p> <ol> <li> Install Swig. <p><a href="http://www.swig.org/">http://www.swig.org/</a> </p> </li><li> Install a Java <small>SDK</small>. Crystal Space has been tested with Sun's Java2 <small>SDK</small>, Standard Edition 1.4.x. After installing Java, be sure that the <samp>‘java’</samp> and <samp>‘javac’</samp> commands are found by your <samp>‘PATH’</samp> environment variable, or set <samp>‘JAVA_HOME’</samp>. <p><a href="http://java.sun.com/j2ee/1.4/download.html">http://java.sun.com/j2ee/1.4/download.html</a> </p> </li><li> Install Ant, a “make”-like tool for Java. After installing Ant, be sure that the <samp>‘ant’</samp> command is found by your <samp>‘PATH’</samp> environment variable, or set <samp>‘ANT_HOME’</samp>. <p><a href="http://ant.apache.org/">http://ant.apache.org/</a> </p> </li><li> Configure Crystal Space. The configure script should recognize the <samp>‘java’</samp>, <samp>‘javac’</samp>, <samp>‘ant’</samp>, and <samp>‘swig’</samp> commands, and perform a “Java SDK usability” check. If all checks succeed, continue to the next step. </li><li> Build and optionally install Crystal Space. The csJava module will be built along with the rest of the project. </li></ol> <p>Once Crystal Space is built and optionally installed, you can use the csJava module in your own programs. To do so, follow these instructions: </p> <ol> <li> Tell Java where to find <tt>‘crystalspace.jar’</tt> by setting your <samp>‘CLASSPATH’</samp> environment variable to point at the <small>JAR</small> file. If you installed Crystal Space, then the <small>JAR</small> file will reside at: <p><code>${prefix}/share/crystalspace/bindings/java/crystalspace.jar</code> </p> <p>where ${prefix} is the installation path (typically, <tt>‘/usr/local’</tt>). If you did not install Crystal space, then the <small>JAR</small> file will be in the top-level build directory (this will be the <tt>‘CS’</tt> directory if you configured and built in the <tt>‘CS’</tt> directory). For convenience in testing, you can also point your <samp>‘CLASSPATH’</samp> variable at the current directory (<samp>‘.’</samp>). </p> </li><li> Tell Java where to find the csJava shared library by setting your <samp>‘LD_LIBRARY_PATH’</samp> environment variable on Unix, your <samp>‘PATH’</samp> variable on Windows, or your <samp>‘DYLD_LIBRARY_PATH’</samp> variable on MacOS/X. On Unix, the library's name is <tt>‘libcsjava.so’</tt>; on Windows it is <tt>‘csjava.dll’</tt>; and on MacOS/X, it is <tt>‘libcsjava.jnilib’</tt>. If you installed Crystal Space, then the library will reside at: <p><code>${prefix}/share/crystalspace/bindings/java</code> </p> <p>If you did not install Crystal Space, then it will be in the top-level build directory. </p> </li><li> If necessary, set your <samp>‘CRYSTAL’</samp> environment variable to allow Crystal Space to locate its plugin modules and other resources. </li><li> In the directory containing your Java program, <tt>‘myprog.java’</tt>, compile it with the <samp>‘javac’</samp> command: <samp>‘javac myprog.java’</samp> </li><li> Run your program: <samp>‘java myprog’</samp> </li></ol> <p>The sample program <tt>‘SimpleRoom.java’</tt> provides a nice example of how to utilize Crystal Space from Java. It provides the same functionality as the first C++ tutorial (see section <a href="Tutorial-Simple.html#0">Simple Tutorial 1: Basic Setup, World Creation</a>). If you installed Crystal Space, then <tt>‘SimpleRoom.java’</tt> will reside at: </p> <p><code>${prefix}/share/crystalspace/bindings/java/SimpleRoom.java</code> </p> <p>If you did not install Crystal Space, then you can find it in the Crystal Space source tree at <tt>‘CS/scripts/java/SimpleRoom.java’</tt>. To experiment with <tt>‘SimpleRoom.java’</tt>, copy it to a convenient work directory, compile it with <samp>‘javac’</samp>, and run it with <samp>‘java’</samp>. Here is a sample session on <small>GNU</small>/Linux illustrating the above instructions: </p> <table><tr><td> </td><td><pre class="example">% cd CS % ./configure ... checking for swig... swig checking if swig version >= 1.3.20... yes (version 1.3.22) checking for java... /usr/java/j2sdk1.4.2_06/bin/java checking for javac... /usr/java/j2sdk1.4.2_06/bin/javac checking if Java2 SDK is usable... yes checking for ant... /usr/local/ant/bin/ant ... % jam install # (or 'make install') % csjavadir=/usr/local/share/crystalspace/bindings/java % CLASSPATH=$CLASSPATH:.:$csjavadir/crystalspace.jar % export CLASSPATH % LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$csjavadir % export LD_LIBRARY_PATH % CRYSTAL=/usr/local % export CRYSTAL % mkdir $HOME/javatest % cd $HOME/javatest % cp $csjavadir/SimpleRoom.java . % javac SimpleRoom.java % java SimpleRoom </pre></td></tr></table> <p>On Windows and MacOS/X, the procedure is almost identical. The primary difference is that, rather than setting <samp>‘LD_LIBRARY_PATH’</samp>, you need to set the <samp>‘PATH’</samp> environment variable on Windows to point at the directory containing <tt>‘csjava.dll’</tt>; or the <samp>‘DYLD_LIBRARY_PATH’</samp> variable on MacOS/X to point at the directory containing <tt>‘libcsjava.jnilib’</tt>. </p> <hr size="1"> <table cellpadding="1" cellspacing="1" border="0"> <tr><td valign="middle" align="left">[<a href="iScript-Interface.html#0" title="Previous section in reading order"> < </a>]</td> <td valign="middle" align="left">[<a href="Perl-Bindings.html#0" title="Next section in reading order"> > </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="Using-Crystal-Space.html#0" title="Beginning of this chapter or previous chapter"> << </a>]</td> <td valign="middle" align="left">[<a href="Scripting-Languages.html#0" title="Up section"> Up </a>]</td> <td valign="middle" align="left">[<a href="Working-with-Engine-Content.html#0" title="Next chapter"> >> </a>]</td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left"> </td> <td valign="middle" align="left">[<a href="index.html#SEC_Top" title="Cover (top) of document">Top</a>]</td> <td valign="middle" align="left">[<a href="cs_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td> <td valign="middle" align="left">[<a href="cs_Index.html#0" title="Index">Index</a>]</td> <td valign="middle" align="left">[<a href="cs_abt.html#SEC_About" title="About (help)"> ? </a>]</td> </tr></table> <p> <font size="-1"> This document was generated using <a href="http://texi2html.cvshome.org/"><em>texi2html 1.76</em></a>. </font> <br> </p> </body> </html>