CDF Version 2.7, UNIX/POSIX Systems The CDF distribution package now contains the CDF Java APIs, in addition to the existing C and Fortran APIs, to allow users to develop platform-independent CDF applications. By default, the Java APIs are not installed as part of standard installation, and the APIs can be installed by following the installation instructions listed below. Documentation for the CDF Java APIs is available at http://nssdc.gsfc.nasa.gov/cdf/cdfjava_doc/index.html. *************************************************************************** * Please make sure that you have done the following before proceeding * * with the CDF Java APIs installation: * * * * - installed JDK 1.2 (preferably 1.3) or later * * - untarred the CDF distribution package * * - installed the CDF distribution package using the 'make' command * * from the cdf27-dist directory. Make sure that CDF is compiled * * with shared library support. * * - executed the definitions.C file located under the cdf27-dist/bin * * directory (e.g. `source definitions.C' for C shell). This file * * defines the environment variables (e.g. CDF_BASE, CDF_LIB, etc) * * that are used by the installation instructions described below. * *************************************************************************** Installation instructions of the CDF Java APIs ---------------------------------------------- 1. Set your current directory (cd) to the top level CDF directory (the directory named `cdf27-dist' created by `tar'). 2. If you downloaded a tar file that contains both the CDF library and the CDF Java APIs (i.e. cdf27-dist-all.tar), go to step 3. Untar the CDF Java APIs, cdf27-dist-java.tar, as follows: tar xvf cdf27-dist-java.tar 3. Set your current directory (cd) to the cdfjava/jni directory. 4. Compile the JNI code, cdfNativeLibrary.c, as follows: cc -c cdfNativeLibrary.c -I${CDF_BASE}/src/include -I -I -o cdfNativeLibrary.o NOTE: During compilation, you may get the following warning message or something similar on some platforms. Don't be alarmed about the message and proceed to the next step. "cdfNativeLibrary.c: In function `getJavaField': cdfNativeLibrary.c:398: warning: assignment discards qualifiers from pointer target type" Examples: The examples below assume that the appropriate environmental variables have been properly defined. The CDF_BASE and CDF_LIB variables are defined in the definitions. file located under the cdf27-dist/bin directory. The JAVA_HOME environment variable refers to the name of the root/base directory where the Java virtual machine is installed. If you have Linux on a PC, the following command will compile the JNI code: gcc -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/linux \ -c cdfNativeLibrary.c For a Sun OS or Solaris sparc, the following command will compile the JNI code into 32-bit mode (using Sun's compiler): cc -DSOLARIS -DHAVE_CONFIG_H \ -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/solaris \ -c cdfNativeLibrary.c For a Solaris sparc (8/9), the following command will compile the JNI code into 64-bit mode (using Sun's compiler): cc -DSOLARIS -DSOLARIS64 -DHAVE_CONFIG_H -xarch=v9a \ -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/solaris \ -c cdfNativeLibrary.c For a Solaris sparc (8/9), the following command will compile the JNI code into 64-bit mode (using Gnu's gcc compiler): gcc -DSOLARIS -DSOLARIS64 -m64 \ -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/solaris -c cdfNativeLibrary.c If you have OSF1 on a DEC Alpha, the following command will compile the JNI code: gcc -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include/java \ -I${JAVA_HOME}/include/java/alpha \ -c cdfNativeLibrary.c If you are using the IBM JDK under Linux, the following command will compile the JNI code: cc -I${CDF_BASE}/src/include \ -I${JAVA_HOME}/include \ -I${JAVA_HOME}/include/linux \ -c cdfNativeLibrary.c If you are using Mac OS X, the following command will compile the JNI code as well as create a shared library. It covers both this step and next step (go to step 6 after successful execution): (Refer Apple's "Mac OS X GM Release Notes: Java" for more information.) cc -bundle \ -I/System/Library/Frameworks/JavaVM.framework/Headers \ -I${CDF_BASE}/src/include \ -framework JavaVM \ -o ../lib/libcdfNativeLibrary.jnilib \ ${CDF_BASE}/lib/libcdf.a \ cdfNativeLibrary.c NOTE: The include path is slightly different depending upon which JDK version and operating system you use. 5. Create a shared library for the JNI code just compiled as follows: If you are using OSF1, Linux, Irix5|6, or AIX, use the following command: ld -shared cdfNativeLibrary.o ${CDF_LIB}/libcdf.so \ -o ../lib/libcdfNativeLibrary.so -lc -lm If you are using a Solaris or Sun OS, use the following command to make a 32-bit mode library: ld -G cdfNativeLibrary.o ${CDF_LIB}/libcdf.so \ -o ../lib/libcdfNativeLibrary.so -lc -lm If you are using a Solaris sparc (8|9), use the following command for Sun's linker to make a 64-bit mode library: ld -G cdfNativeLibrary.o ${CDF_LIB}/libcdf.so \ -64 -L/usr/lib/sparcv9 \ -o ../lib/libcdfNativeLibrary.so -lc -lm Note: assume that 64-bit library is at /usr/lib/sparcv9. If you are using a Solaris sparc (8|9), use the following command for Gnu's gcc linker to make a 64-bit mode library: gcc -G cdfNativeLibrary.o ${CDF_LIB}/libcdf.so \ -m64 -L/usr/local/gcc-3.2/lib/sparcv9 \ -o ../lib/libcdfNativeLibrary.so -lc -lm Note: assume that Gnu's 64-bit library is at /usr/local/gcc-3.2/lib/sparcv9. If you are using HP-UX, use the following command: ld -b cdfNativeLibrary.o ${CDF_LIB}/libcdf.sl \ -o ../lib/libcdfNativeLibrary.sl -lc -lm 6. Set the CLASSPATH and LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Mac OS X) environment variables. 1) CLASSPATH should point to the following file(s): - the location (full path name) of the cdfjava.jar file that is included in cdfjava.tar. It's located in the cdfjava/classes directory. Example: setenv CLASSPATH ${CLASSPATH}:.: \ /home/cdf/cdf27-dist/cdfjava/classes/cdfjava.jar Optionally, if the Java-based CDF tools will be used, then also include CDFToolsDriver.jar in the CLASSPATH. This jar file resides in the cdfjava/cdftools directory. 2) LD_LIBRARY_PATH should point to the following files: - the location (full path name) of the libcdfNativeLibrary.[so|sl|jnilib] created in step 5 (it should be under cdfjava/lib) - the location (full path name) of the CDF library (libcdf.[so|sl|jnilib] that is defined by the environment variable CDF_LIB that is defined when the CDF library is installed. Example: setenv LD_LIBRARY_PATH .:/home/cdf/cdf27-dist/cdfjava/lib:${CDF_LIB} Or for Mac OS X, setenv DYLD_LIBRARY_PATH .:/home/cdf/cdf27-dist/cdfjava/lib:${CDF_LIB}