How to build VTK4.4.2  on Solaris 9/10 with Java1.5

Xiaoli Dong

Sun Center of Excellence for Visual Genomics


 you must compile vtk from source by yourself if you want to use VTK with Java Wrapper enabled,

Download and Unpack VTK


Download vtk source from  http://www.vtk.org/get-software.php and use the following command to unpack it:

#gunzip -d vtk-4.4.2.tar.gz

#tar -xvf vtk-4.4.2.tar

You will get a directory called VTK

Preparation for compiling VTK


Before you compile VTK, you should set up the following environment variables. For example:

setenv JAVA_HOME your_Java_directory
setenv CC your_C_Compiler ( i.e. /usr/sfw/bin/gcc)
setenv CXX you_C++_Compiler (i.e. /usr/sfw/bin/g++)

Check whether you have CMake. The required CMake must be version 2.0 or higher.
If you don't have it, go to http://www.cmake.org/HTML/Download.html to download and install it

Compile VTK

The defaut configuration files that comes with CMake are for Windows, i386 and  I didn't find any configuration for SPARC. So, I wrote the following FindJNI.cmake based on CMake's default FindJNI.cmake and put it into VTK directory

# ls -d VTK
VTK/

#cd VTK
#emacs CMakeLists.txt   to edit it

See my final CMakeLists.txt file

The lines between #xiaoli  and #xiaoli end is what I added

# cd ../.

# mkdir VTK-build
#mkdir VTK-install

#cd VTK-build
#ccmake ../VTK

configure all the paramenter through CMake text interface.  Click the CMakeCache.txt to see the parameters that I used to compile VTK

#gmake

Install VTK

#ls -d VTK-build
VTK-build/

#gmake install

VTK will be installed into the target directory that you configured in CMake text interface. In my case, it's VTK-install. and It will generate the following sub directory:
bin          include      lib

Build the JAR

If you're lucky, this has already been done for you by gmake, and there's a file called vtk.jar in ~/VTK-build/bin. However, I didn't get it and I did the following from ~/VTK-build:

#cd java
#mkdir classes/
#javac -d classes/ vtk/*.java
#cd classes/
#jar cvf vtk.jar vtk/
#jar i vtk.jar
#cp vtk.jar VTK-install

Run VTK Tutorial

In order to run tutorial, you will need vtkPanel.java get compiled. run the following command to compile it and jar it into vtk.jar

#cd  VTK/Wrapping/Java/vtk
#javac -d . vtkPanel.java vtkCanvas.java
#jar -uvf VTK-install/vtk.jar vtk 

Before you run the tutorial, you need to set up the following variables:

setenv VTK VTK-install (VTK installation directory)
setenv CLASSPATH .:$VTK/vtk.jar
append the dynamic link library to your LD_LIBRARY_PATH path.  I appended the following to my LD_LIBRARY_PATH path when I running vtk in coe46
:/opt/sfw/lib:$JAVA_HOME/jre/lib//sparc/xawt:$VTK/lib/vtk


Now you are ready to test and run VTK

Download the following examples to see whether your vtk set up is all right or not

Download Tutorial  and run the following command:

# tar -xvf Tutorial.tar
Comile the sample program and run it.