Creating Jar Files For Java Routines - IBM DB2 Manual

Table of Contents

Advertisement

The steps in the process are:
1. Run the sqlj command to translate the source code to produce generated Java
source code and serialized profiles, and to compile the Java program to
produce Java bytecodes.
2. Run the db2sqljcustomize command to produce serialized profiles that are
customized for DB2 for z/OS and DB2 packages.
3. Ensure that the zFS or HFS directory that contains the class files for your
routine is in the CLASSPATH for the WLM-established stored procedure
address space.
You specify this CLASSPATH in the JAVAENV data set. You specify the
JAVAENV data set using a JAVAENV DD statement in the startup procedure
for the WLM-established stored procedure address space.
If you need to modify the CLASSPATH environment variable in the JAVAENV
data set to include the directory for the Java routine's classes, you must restart
the WLM address space to make it use the modified CLASSPATH.
4. Use the SQL CREATE PROCEDURE or CREATE FUNCTION statement to
define the routine to DB2. Specify the EXTERNAL NAME parameter without a
JAR name.
5. Execute the SQL GRANT statement to grant the EXECUTE privilege on the
routine to the appropriate users.
Related concepts
"Run-time environment for Java routines" on page 160
Related tasks
"Program preparation for SQLJ programs" on page 183

Creating JAR files for Java routines

A convenient way to ensure that all modules of a Java routine are accessible is to
store those modules in a JAR file. You create the JAR file by running the jar
command in z/OS UNIX System Services.
The source code must be compiled. For Java routines with SQLJ clauses, the source
code must be translated, compiled, and customized.
To create the JAR file, follow these steps:
1. If the Java source file does not contain a package statement, change to the
directory that contains the class file for the Java routine, which you created by
running the javac command.
For example, if JDBC routine Add_customer.java is in /u/db2res3/acmejos,
change to directory /u/db2res3/acmejos.
If the Java source file contains a package statement, change to the directory that
is one level above the directory that is named in the package statement.
For example, suppose the package statement is:
package lvlOne.lvlTwo.lvlThree;
Change to the directory that contains lvlOne as an immediate subdirectory.
2. Run the jar command.
You might need to specify at least these options:
c
Creates a new or empty archive.
v
Generates verbose output on stderr.
Chapter 6. Preparing and running JDBC and SQLJ programs
191

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents