Oracle® Database Java Developer's Guide, 11g Release 2 (11.2) Part Number E10588-01 |
|
|
View PDF |
This chapter describes the schema objects that you use in Oracle Database Java environment and Oracle JVM utilities. You run these utilities from a UNIX shell or from the Microsoft Windows DOS prompt.
Note:
All names supplied to these tools are case-sensitive. As a result, the schema, user name, and password should not be changed to uppercase.This chapter contains the following sections:
Unlike conventional Java virtual machine (JVM), which compiles and loads Java files, Oracle JVM compiles and loads schema objects. The following kinds of Java schema objects are loaded:
Java class schema objects, which correspond to Java class files.
Java source schema objects, which correspond to Java source files.
Java resource schema objects, which correspond to Java resource files.
To ensure that a class file can be run by Oracle JVM, you must use the loadjava
tool to create a Java class schema object from the class file or the source file and load it into a schema. To make a resource file accessible to Oracle JVM, you must use the loadjava
tool to create and load a Java resource schema object from the resource file.
The dropjava
tool deletes schema objects that correspond to Java files. You should always use the dropjava
tool to delete a Java schema object that was created with the loadjava
tool. Dropping schema objects using SQL data definition language (DDL) commands will not update auxiliary data maintained by the loadjava
tool and the dropjava
tool.
You must load resource files using the loadjava
tool. If you create .class
files outside the database with a conventional compiler, then you must load them with the loadjava
tool. The alternative to loading class files is to load source files and let Oracle Database compile and manage the resulting class schema objects. In Oracle Database 11g, the most productive approach is to compile and debug most of your code outside the database, and then load the .class
files. For a particular Java class, you can load either its .class
file or the corresponding .java
file, but not both.
The loadjava
tool accepts Java Archive (JAR) files that contain either source and resource files or class and resource files. When you pass a JAR or ZIP file to the loadjava
tool, it opens the archive and loads its members individually. There are no JAR or ZIP schema objects.
Note:
When you load the contents of a JAR into the database, you have the option of creating a database object representing the JAR itself. For more information, refer to "Database Resident JARs".A file, whose content has not changed since the last time it was loaded, is not reloaded. As a result, there is little performance penalty for loading JAR files. Loading JAR files is a simple, fool-proof way to use the loadjava
tool.
It is illegal for two schema objects in the same schema to define the same class. For example, assume that a.java
defines class x
and you want to move the definition of x
to b.java
. If a.java
has already been loaded, then the loadjava
tool will reject an attempt to load b.java
. Instead, do either of the following:
Drop a.java
, load b.java
, and then load the new a.java
, which does not define x
.
Load the new a.java
, which does not define x
, and then load b.java
.
All Java classes contain references to other classes. A conventional JVM searches for classes in the directories, ZIP files, and JAR files named in the CLASSPATH
. In contrast, Oracle JVM searches schemas for class schema objects. Each class in the database has a resolver specification, which is Oracle Database counterpart to CLASSPATH
. For example, the resolver specification of a class, alpha
, lists the schemas to search for classes that alpha
uses. Notice that resolver specifications are per-class, whereas in a classic JVM, CLASSPATH
is global to all classes.
In addition to a resolver specification, each class schema object has a list of interclass reference bindings. Each reference list item contains a reference to another class and one of the following:
The name of the class schema object to call when the class uses the reference
A code indicating whether the reference is unsatisfied, that is, whether the referent schema object is known
Oracle Database facility known as resolver maintains reference lists. For each interclass reference in a class, the resolver searches the schemas specified by the resolver specification of the class for a valid class schema object that satisfies the reference. If all references are resolved, then the resolver marks the class valid. A class that has never been resolved, or has been resolved unsuccessfully, is marked invalid. A class that depends on a schema object that becomes invalid is also marked invalid at the time the first class is marked invalid. In other words, invalidation cascades upward from a class to the classes that use it and the classes that use these classes, and so on. When resolving a class that depends on an invalid class, the resolver first tries to resolve the referenced class, because it may be marked invalid only because it has never been resolved. The resolver does not resolve classes that are marked valid.
A developer can direct the loadjava
tool to resolve classes or can defer resolution until run time. The resolver runs automatically when a class tries to load a class that is marked invalid. It is best to resolve before run time to learn of missing classes early. Unsuccessful resolution at run time produces a ClassNotFound
exception. Furthermore, run-time resolution can fail for the following reasons:
Lack of database resources, if the tree of classes is very large
Deadlocks due to circular dependencies
The loadjava
tool has two resolution modes:
Load-and-resolve
The -resolve
option loads all classes you specify on the command line, marks them invalid, and then resolves them. Use this mode when initially loading classes that refer to each other, and, in general, when reloading isolated classes as well. By loading all classes and then resolving them, this mode avoids the error message that occurs if a class refers to a class that will be loaded later while the command is being carried out.
Load-then-resolve
This mode resolves each class at run time. The -resolve
option is not specified.
Note:
As with a Java compiler, theloadjava
tool resolves references to classes but not to resources. Ensure that you correctly load the resource files that your classes need.If you can, defer resolution until all classes have been loaded. This avoids a situation in which the resolver marks a class invalid because a class it uses has not yet been loaded.
The schema object digest table is an optimization that is usually invisible to developers. The digest table enables the loadjava
tool to skip files that have not changed since they were last loaded. This feature improves the performance of makefiles and scripts that call the loadjava
tool for collections of files, some of which must be reloaded. A reloaded archive file might also contain some files that have changed since they were last loaded and some that have not.
The loadjava
tool detects unchanged files by maintaining a digest table in each schema. The digest table relates a file name to a digest, which is a shorthand representation or a hash, of the content of the file. Comparing digests computed for the same file at different times is a fast way to detect a change in the content of the file. This is much faster than comparing every byte in the file. For each file it processes, the loadjava
tool computes a digest of the content of the file and then looks up the file name in the digest table. If the digest table contains an entry for the file name that has an identical digest, then the loadjava
tool does not load the file, because a corresponding schema object exists and is up to date. If you call the loadjava
tool with the -verbose
option, then it will show you the results of its digest table lookups.
Typically, the digest table is invisible to developers, because the loadjava
tool and the dropjava
tool keep the table synchronized with schema object additions, changes, and deletions. For this reason, always use the dropjava
tool to delete a schema object that was created with the loadjava
tool, even if you know how to drop a schema object using DDL.
Loading a source file creates or updates a Java source schema object and invalidates the class schema objects previously derived from the source. If the class schema objects do not exist, then the loadjava
tool creates them. The loadjava
tool invalidates the old class schema objects because they were not compiled from the newly loaded source. Compilation of a newly loaded source, for example, class A
, is automatically triggered by any of the following conditions:
The resolver, while working on class B
, finds that class B
refers to class A
, but class A
is invalid.
The compiler, while compiling the source of class B
, finds that class B
refers to class A
, but class A
is invalid.
The class loader, while trying to load class A
for running it, finds that class A
is invalid.
To force compilation when you load a source file, use the loadjava -resolve
option.
The compiler writes error messages to the predefined USER_ERRORS
view. The loadjava
tool retrieves and displays the messages produced by its compiler invocations.
The compiler recognizes some options. There are two ways to specify options to the compiler. If you run the loadjava
tool with the -resolve
option, then you can specify compiler options on the command line. You can additionally specify persistent compiler options in a per-schema database table, JAVA$OPTIONS
. You can use the JAVA$OPTIONS
table for default compiler options, which you can override selectively using a loadjava
tool option.
Note:
A command-line option overrides and clears the matching entry in theJAVA$OPTIONS
table.A JAVA$OPTIONS
row contains the names of source schema objects to which an option setting applies. You can use multiple rows to set the options differently for different source schema objects. The compiler looks up options in JAVA$OPTIONS
when it has been called by the class loader or when called from the command line without specifying any options. When compiling a source schema object for which there is neither a JAVA$OPTIONS
entry nor a command-line value for an option, the compiler assumes a default value, as follows:
The ojvmtc
tool enables you to resolve all external references, prior to running the loadjava
tool. The ojvmtc
tool allows the specification of a classpath that specifies the JARs, classes, or directories to be used to resolve class references. When an external reference cannot be resolved, this tool either produces a list of unresolved references or generated stub classes to allow resolution of the references, depending on the options specified. Generated stub classes throw a java.lang.ClassNotfoundException,
if it is referenced at runtime.
The syntax is:
ojvmtc [-help ] [-bootclasspath] [-server connect_string] [-jar jar_name] [-list] -classpath jar1:path2:jar2 jars,...,classes
For example:
ojvmtc -bootclasspath $JAVA_HOME/jre/lib/rt.jar -classpath classdir/lib1.jar:classdir/lib2.jar -jar set.jar app.jar
The preceding example uses rt.jar, classdir/lib1.jar,
and classdir/lib2.jar
to resolve references in app.jar.
All the classes examined are added to set.jar,
except for those found in rt.jar.
Another example is:
ojvmtc -server thin@scott:localhost:5521:orcl -classpath jar1:jar2 -list app2.jar
Password:password
The preceding example uses classes found in the server specified by the connection string as well as jar1
and jar2
to resolve app2.jar.
Any missing references are displayed to stdout.
Table 11-1 summarizes the arguments of this command.
Table 11-1 ojvmtc Argument Summary
Argument | Description |
---|---|
|
Uses the specified JARs and classes for the closure set. |
|
Uses the specified classes for closure, but does not include them in the closure set. |
|
Connects to the server using visible classes in the same manner as |
|
Connects to the server using thin or Oracle Call Interface (OCI) specific driver. If you use thin driver, the syntax is as follows: thin:user/passwd@host:port:sid If you use OCI driver, the syntax is as follows: oci:user/passwd@host:port:sid oci:user/passwd@tnsname oci:user/passwd@(connect descriptor) |
|
Writes each class of the closure set to a JAR and generates stubs for missing classes |
|
Lists the missing classes. |
The loadjava
tool creates schema objects from files and loads them into a schema. Schema objects can be created from Java source, class, and data files. The loadjava
tool can also create schema objects from SQLJ files.
You must have the following SQL database privileges to load classes:
CREATE PROCEDURE
and CREATE TABLE
privileges to load into your schema.
CREATE ANY PROCEDURE
and CREATE ANY TABLE
privileges to load into another schema.
oracle.aurora.security.JServerPermission.loadLibraryInClass.
classname
.
You can run the loadjava
tool either from the command line or by using the loadjava
method contained in the DBMS_JAVA
class. To run the tool from within your Java application, do the following:
call dbms_java.loadjava('... options...');
The options are the same as those that can be specified on the command line with the loadjava
tool. Separate each option with a space. Do not separate the options with a comma. The only exception for this is the -resolver
option, which contains spaces. For -resolver
, specify all other options in the first input parameter and the -resolver
options in the second parameter, as follows:
call dbms_java.loadjava('..options...', 'resolver_options');
Do not specify the -thin
, -oci
, -user
, and -password
options, because they relate to the database connection for the loadjava
command-line tool. The output is directed to stderr
. Set serveroutput
on, and call dbms_java.set_output
, as appropriate.
Note:
Theloadjava
tool is located in the bin
directory under $ORACLE_HOME
.Just before the loadjava
tool exits, it checks whether the processing was successful. All failures are summarized preceded by the following header:
The following operations failed
Some conditions, such as losing the connection to the database, cause the loadjava
tool to terminate prematurely. These errors are displayed with the following syntax:
exiting: error_reason
This section covers the following:
The syntax of the loadjava
tool command is as follows:
loadjava {-user | -u} user/[password][@database] [options] file.java | file.class | file.jar | file.zip | file.sqlj | resourcefile | URL... [-casesensitivepub] [-cleargrants] [-debug] [-d | -definer] [-dirprefix prefix] [-e | -encoding encoding_scheme] [-fileout file] [-f | -force] [-genmissing] [-genmissingjar jar_file] [-g | -grant user [, user]...] [-help] [-jarasresource] [-noaction] [-norecursivejars] [-nosynonym] [-nousage] [-noverify] [-o | -oci | oci8] [-optiontable table_name] [-publish package] [-pubmain number] [-recursivejars] [-r | -resolve] [-R | -resolver "resolver_spec"] [-resolveonly] [-S | -schema schema] [-stdout] [-stoponerror] [-s | -synonym] [-tableschema schema] [-t | -thin] [-unresolvedok] [-v | -verbose] [-jarsasdbobjects] [-prependjarnames] [-nativecompile]
Table 11-2 summarizes the loadjava
tool command arguments. If you run the loadjava
tool multiple times specifying the same files and different options, then the options specified in the most recent invocation hold. However, there are two exceptions to this, as follows:
If the loadjava
tool does not load a file because it matches a digest table entry, then most options on the command line have no effect on the schema object. The exceptions are -grant
and -resolve
, which always take effect. You must use the -force
option to direct the loadjava
tool to skip the digest table lookup.
The -grant
option is cumulative. Every user specified in every invocation of the loadjava
tool for a given class in a given schema has the EXECUTE
privilege.
Table 11-2 loadjava Argument Summary
This section describes the details of some of the loadjava
tool arguments whose behavior is more complex than the summary descriptions contained in Table 11-2.
You can specify as many .class
, .java
, .sqlj
, .jar
, .zip
, and resource files as you want and in any order. If you specify a JAR or ZIP file, then the loadjava
tool processes the files in the JAR or ZIP. There is no JAR or ZIP schema object. If a JAR or ZIP contains another JAR or ZIP, the loadjava
tool does not process them.
The best way to load files is to put them in a JAR or ZIP and then load the archive. Loading archives avoids the resource schema object naming complications. If you have a JAR or ZIP that works with the Java Development Kit (JDK), then you can be sure that loading it with the loadjava
tool will also work, without having to learn anything about resource schema object naming.
Schema object names are different from file names, and the loadjava
tool names different types of schema objects differently. Because class files are self-identifying, the mapping of class file names to schema object names done by the loadjava
tool is invisible to developers. Source file name mapping is also invisible to developers. The loadjava
tool gives the schema object the fully qualified name of the first class defined in the file. JAR and ZIP files also contain the names of their files.
However, resource files are not self identifying. The loadjava
tool generates Java resource schema object names from the literal names you supply as arguments. Because classes use resource schema objects and the correct specification of resources is not always intuitive, it is important that you specify resource file names correctly on the command line.
The perfect way to load individual resource files correctly is to run the loadjava
tool from the top of the package tree and specify resource file names relative to that directory.
Note:
The top of the package tree is the directory you would name in aCLASSPATH
.If you do not want to follow this rule, then observe the details of resource file naming that follow. When you load a resource file, the loadjava
tool generates the resource schema object name from the resource file name, as literally specified on the command line. For example, if you type:
% cd /home/scott/javastuff % loadjava options alpha/beta/x.properties % loadjava options /home/scott/javastuff/alpha/beta/x.properties
Although you have specified the same file with a relative and an absolute path name, the loadjava
tool creates two schema objects, alpha/beta/x.properties
and ROOT/home/scott/javastuff/alpha/beta/x.properties
. The name of the resource schema object is generated from the file name as entered.
Classes can refer to resource files relatively or absolutely. To ensure that the loadjava
tool and the class loader use the same name for a schema object, enter the name on the command line, which the class passes to getResource()
or getResourceAsString()
.
Instead of remembering whether classes use relative or absolute resource names and changing directories so that you can enter the correct name on the command line, you can load resource files in a JAR, as follows:
% cd /home/scott/javastuff % jar -cf alpharesources.jar alpha/*.properties % loadjava options alpharesources.jar
To simplify the process further, place both the class and resource files in a JAR, which makes the following invocations equivalent:
% loadjava options alpha.jar % loadjava options /home/scott/javastuff/alpha.jar
The preceding loadjava
tool commands imply that you can use any path name to load the contents of a JAR file. Even if you run the redundant commands, the loadjava
tool would realize from the digest table that it need not load the files twice. This implies that reloading JAR files is not as time-consuming as it might seem, even when few files have changed between the different invocations of the loadjava
tool.
definer
{-definer | -d}
This option is identical to the definer rights in stored procedures and is conceptually similar to the UNIX setuid
facility. However, you can apply the -definer
option to individual classes, in contrast to setuid
, which applies to a complete program. Moreover, different definers may have different privileges. Because an application can consist of many classes, you must apply -definer
with care to achieve the desired results. That is, classes run with the privileges they need, but no more.
See Also:
"Controlling the Current User"noverify
[-noverify]
This option causes the classes to be loaded without bytecode verification. oracle.aurora.security.JServerPermission(Verifier)
must be granted to run this option. Also, this option must be used in conjunction with -resolve
.
The verifier ensures that incorrectly formed Java binaries cannot be loaded for running on the server. If you know that the JAR or classes you are loading are valid, then the use of this option will speed up the process associated with the loadjava
tool. Some Oracle Database-specific optimizations for interpreted performance are put in place during the verification process. Therefore, the interpreted performance of your application may be adversely affected by using this option.
optionfile
[-optionfile <file>]
This option enables you to specify a file with different options that you can specify with the loadjava
tool. This file is read and processed by the loadjava
tool before any other loadjava
tool options are processed. The file can contain one or more lines, each of which contains a pattern and a sequence of options. Each line must be terminated by a newline character (\n
).
For each file or JAR entry that is processed by the loadjava
tool, the long name of the schema object that is going to be created is checked against the patterns. Patterns can end in a wildcard (*
) to indicate an arbitrary sequence of characters, or they must match the name exactly.
Options to be applied to matching Java schema objects are supplied on the rest of the line. Options are appended to the command-line options, they do not replace them. In case more than one line matches a name, the matching rows are sorted by length of pattern, with the shortest first, and the options from each row are appended. In general, the loadjava
tool options are not cumulative. Rather, later options override earlier ones. This means that an option specified on a line with a longer pattern will override a line with a shorter pattern.
This file is parsed by a java.io.StreamTokenizer
.
You can use Java comments in this file. A line comment begins with a #
. Empty lines are ignored. The quote character is a double quote ("
). That is, options containing spaces should be surrounded by double quotes. Certain options, such as -user
and -verbose
, affect the overall processing of the loadjava
tool and not the actions performed for individual Java schema objects. Such options are ignored if they appear in an option file.
To help package applications, the loadjava
tool looks for the META-INF/loadjava-options
entry in each JAR it processes. If it finds such an entry, then it treats it as an options file that is applied for all other entries in the option file. However, the loadjava
tool does some processing on entries in the order in which they occur in the JAR.
If the loadjava
tool has partially processed entities before it processes META-INF/loadjava-options
, then it attempts to patch up the schema object to conform to the applicable options. For example, the loadjava
tool alters classes that were created with invoker rights when they should have been created with definer rights. The fix for -noaction
is to drop the created schema object. This yields the correct effect, except that if a schema object existed before the loadjava
tool started, then it would have been dropped.
publish
[-publish <package>] [-pubmain <number>]
The publishing options cause the loadjava
tool to create PL/SQL wrappers for methods contained in the processed classes. Typically, a user wants to publish wrappers for only a few classes in a JAR. These options are most useful when specified in an option file.
To be eligible for publication, the method must satisfy the following:
It must be a member of a public
class.
It must be declared public
and static
.
The method signature should satisfy the following rules so that it can be mapped:
Java arithmetic types for arguments and return values are mapped to NUMBER
.
char
as an argument and return type is mapped to VARCHAR
.
java.lang.String
as an argument and return type is mapped to VARCHAR
.
If the only argument of the method has type java.lang.String
, special rules apply, as listed in the -pubmain
option description.
If the return type is void
, then a procedure is created.
If the return type is an arithmetic, char
, or java.lang.String
type, then a function is created.
Methods that take arguments or return types that are not covered by the preceding rules are not eligible. No provision is made for OUT
and IN OUT
SQL arguments, OBJECT
types, and many other SQL features.
resolve
{-resolve | -r}
Use -resolve
to force the loadjava
tool to compile and resolve a class that has previously been loaded. It is not necessary to specify -force
, because resolution is performed after, and independent of, loading.
resolver
{-resolver | -R} resolver_specification
This option associates an explicit resolver specification with the class schema objects that the loadjava
tool creates or replaces.
A resolver specification consists of one or more items, each of which consists of a name specification and a schema specification expressed in the following syntax:
"((name_spec schema_spec) [(name_spec schema_spec)] ...)"
A name specification is similar to a name in an import
statement. It can be a fully qualified Java class name or a package name whose final element is the wildcard character asterisk (*
) or simply an asterisk (*
). However, the elements of a name specification must be separated by slashes (/
), not periods (.
). For example, the name specification a/b/*
matches all classes whose names begin with a.b
. The special name *
matches all class names.
A schema specification can be a schema name or the wildcard character dash (-
). The wildcard does not identify a schema, but directs the resolve operation not to mark a class invalid, because a reference to a matching name cannot be resolved. Use dash (-
) when you must test a class that refers to a class you cannot or do not want to load. For example, GUI classes that a class refers to but does not call, because when run in the server there is no GUI.
When looking for a schema object whose name matches the name specification, the resolution operation looks in the schema named by the partner schema specification.
The resolution operation searches schemas in the order in which the resolver specification lists them. For example,
-resolver '((* SCOTT) (* PUBLIC))'
This implies that search for any reference first in SCOTT
and then in PUBLIC
. If a reference is not resolved, then mark the referring class invalid and display an error message.
Consider the following example:
-resolver "((* SCOTT) (* PUBLIC) (my/gui/* -))"
This implies that search for any reference first in SCOTT
and then in PUBLIC
. If the reference is to a class in the package my.gui
and is not found, then mark the referring class valid and do not display an error. If the reference is not to a class in my.gui
and is not found, then mark the referring class invalid and produce an error message.
user
{-user | -u} user/password[@database_url]
By default, the loadjava
tool loads into the logged in schema specified by the -user
option. You use the -schema
option to specify a different schema to load into. This does not require you to log in to that schema, but does require that you have sufficient permissions to alter the schema.
The permissible forms of @
database_url
depend on whether you specify -oci
or -thin
, as described:
-oci:@
database_url
is optional. If you do not specify, then the loadjava
tool uses the user's default database. If specified, database_url
can be a TNS name or an Oracle Net Services name-value list.
-thin:@
database_url
is required. The format is host
:
lport
:
SID
.
where:
host
is the name of the computer running the database.
lport
is the listener port that has been configured to listen for Oracle Net Services connections. In a default installation, it is 5521
.
SID
is the database instance identifier. In a default installation, it is ORCL
.
The following are examples of the loadjava
tool commands:
Connect to the default database with the default OCI driver, load the files in a JAR into the TEST
schema, and then resolve them:
loadjava -u joe -resolve -schema TEST ServerObjects.jar
Password: password
Connect with the JDBC Thin driver, load a class and a resource file, and resolve each class:
loadjava -thin -u SCOTT@dbhost:5521:orcl \
-resolve alpha.class beta.props
Password: password
Add Betty and Bob to the users who can run alpha.class
:
loadjava -thin -schema test -u SCOTT@localhost:5521:orcl \ -grant BETTY,BOB alpha.class Password: password
jarsasdbobjects
This option indicates that JARs processed by the current loadjava
tool are to be stored in the database along with the classes they contain, and knowledge of the association between the classes and the JAR is to be retained in the database. In other words, this argument indicates that the JARs processed by the current loadjava
tool are to be stored in the database as database resident JARs.
prependjarnames
This option is used with the -jarsasdbobjects
option. This option enables classes with the same names coming from different JARs to coexist in the same schema.
The dropjava
tool is the converse of the loadjava
tool. It transforms command-line file names and JAR or ZIP file contents to schema object names, drops the schema objects, and deletes their corresponding digest table rows. You can enter .java
, .class
, .sqlj
, .ser
, .zip
, .jar
, and resource file names on the command line and in any order.
Alternatively, you can specify a schema object name directly to the dropjava
tool. A command-line argument that does not end in .jar
, .zip
, .class
, .java
, or .sqlj
is presumed to be a schema object name. If you specify a schema object name that applies to multiple schema objects, then all will be removed.
Dropping a class invalidates classes that depend on it, recursively cascading upwards. Dropping a source drops classes derived from it.
Note:
You must remove Java schema objects in the same way that you first loaded them. If you load a.sqlj
source file and translate it in the server, then you must run the dropjava
tool on the same source file. If you translate on a client and load classes and resources directly, then run the dropjava
tool on the same classes and resources.You can run the dropjava
tool either from the command line or by using the dropjava
method in the DBMS_JAVA
class. To run the dropjava
tool from within your Java application, use the following command:
call dbms_java.dropjava('... options...');
The options are the same as specified on the command line. Separate each option with a space. Do not separate the options using commas. The only exception to this is the -resolver
option. The connection is always made to the current session. Therefore, you cannot specify another user name through the -user
option.
For -resolver
, you should specify all other options first, a comma (,
), then the -resolver
option with its definition. Do not specify the -thin
, -oci
, -user
, and -password
options, because they relate to the database connection for the loadjava
tool. The output is directed to stderr
. Set serveroutput
on and call dbms_java.set_output
, as appropriate.
This section covers the following topics:
The syntax of the dropjava
tool command is:
dropjava [options] {file.java | file.class | file.sqlj | file.jar | file.zip | resourcefile} ... -u | -user user/[password][@database] [-genmissingjar JARfile] [-jarasresource] [-o | -oci | -oci8] [-optionfile file] [-S | -schema schema] [-stdout] [-s | -synonym] [-t | -thin] [-v | -verbose]
Table 11-3 summarizes the dropjava
tool arguments.
Table 11-3 dropjava Argument Summary
Argument | Description |
---|---|
|
Specifies a user name, password, and optional database connection string. The files will be dropped from this database instance. |
|
Specifies any number and combination of |
|
Treats the operand of this option as a file to be processed. |
|
Drops the whole JAR file, which was previously loaded as a resource. |
|
Directs the |
|
Has the same usage as for the |
|
Designates the schema from which schema objects are dropped. If not specified, then the logon schema is used. To drop a schema object from a schema that is not your own, you need the |
|
Causes the output to be directed to |
|
Drops a |
|
Directs the |
|
Directs the |
|
Drops the classes, Java source, or resources listed on the command line without them being present on the client machine or server machine. |
|
Reads a file and drops the classes, Java source, or resources listed in the file without them being present on the client machine or server machine.The file contains the internal representation of the complete class, Java source, or resource name one per line. |
This section describes a few of the dropjava
tool arguments, which are complex.
The dropjava
tool interprets most file names as the loadjava
tool does:
.class
files
Finds the class name in the file and drops the corresponding schema object.
.java
and .sqlj
files
Finds the first class name in the file and drops the corresponding schema object.
.jar
and .zip
files
Processes the archived file names as if they had been entered on the command line.
If a file name has another extension or no extension, then the dropjava
tool interprets the file name as a schema object name and drops all source, class, and resource objects that match the name.
If the dropjava
tool encounters a file name that does not match a schema object, then it displays a message and processes the remaining file names.
user
{-user | -u} user/password[@database]
The permissible forms of @
database
depend on whether you specify -oci
or -thin
:
-oci:@
database
is optional. If you do not specify, then the dropjava
tool uses the user's default database. If specified, then database
can be a TNS name or an Oracle Net Services name-value list.
-thin:@
database
is required. The format is host
:
lport
:
SID
.
where:
host
is the name of the computer running the database.
lport
is the listener port that has been configured to listen for Oracle Net Services connections. In a default installation, it is 5521
.
SID
is the database instance identifier. In a default installation, it is ORCL
.
The following are examples of the dropjava
tool command:
Drop all schema objects in the TEST
schema in the default database that were loaded from ServerObjects.jar
:
dropjava -u SCOTT -schema TEST ServerObjects.jar
Password: password
Connect with the JDBC Thin driver, then drop a class and a resource file from the user's schema:
dropjava -thin -u SCOTT@dbhost:5521:orcl alpha.class beta.props
Password: password
List Based Deletion
Earlier versions of the dropjava
tool required that the classes, JARs, source, and resources be present on the machine, where the client or server side utility is running. The current version of dropjav
a has an option that enables you to drop classes, resources, or sources based on a list of classes, which may not exist on the client machine or the server machine. This list can be either on the command line or in a text file. For example:
dropjava –list –u scott –v this.is.my.class this.is.your.class
Password: password
The preceding command drops the classes this.is.my.class
and this.is.your.class
listed on the command line without them being present on the client machine or server machine.
dropjava –listfile my.list –u scott –s –v
Password: password
The preceding command drops classes, resources, or sources and their synonyms based on a list of classes listed in my.list
and displays verbosely.
Care must be taken if you are removing a resource that was loaded directly into the server. This includes profiles, if you translated them on the client without using the -ser2class
option. When dropping source or class schema objects or resource schema objects that were generated by the server-side SQLJ translator, the schema objects will be found according to the package specification in the applicable .sqlj
source file. However, the fully qualified schema object name of a resource that was generated on the client and loaded directly into the server depends on path information in the .jar
file or that specified on the command line at the time you loaded it. If you use a .jar
file to load resources and use the same .jar
file to remove resources, then there will be no problem. However, if you use the command line to load resources, then you must be careful to specify the same path information when you run the dropjava
tool to remove the resources.
The ojvmjava
tool is an interactive interface to the session namespace of a database instance. You specify database connection arguments when you start the ojvmjava
tool. It then presents you with a prompt to indicate that it is ready for commands.
The shell can launch an executable, that is, a class with a static main()
method. This is done either by using the command-line interface or by calling a database resident class. If you call a database resident class, the executable must be loaded with the loadjava
tool.
This section covers the following topics:
The syntax of the ojvmjava
tool command is:
ojvmjava {-user user[/password@database ] [options] [@filename] [-batch] [-c | -command command args] [-debug] [-d | -database conn_string] [-fileout filename] [-o | -oci | -oci8] [-oschema schema] [-t | -thin] [-version | -v] -runjava [server_file_system] -jdwp port [host] -verbose
Table 11-4 summarizes the ojvmjava
tool arguments.
Table 11-4 ojvmjava Argument Summary
Argument | Description |
---|---|
|
Specifies user name for connecting to the database. This name is not case-sensitive. The name will always be converted to uppercase. If you provide the database information, then the default syntax used is OCI. You can also specify the default database. |
|
Specifies the password for connecting to the database. This is not case-sensitive and will always be converted to uppercase. |
|
Specifies a script file that contains the |
|
Disables all messages displayed to the screen. No help messages or prompts will be displayed. Only responses to commands entered are displayed. |
|
Runs the desired command. If you do not want to run the |
|
Displays debugging information. |
|
Provide a database connection string. |
|
Redirect output to the provided file. |
|
Uses the JDBC OCI driver. The OCI driver is the default. This flag specifies the syntax used in either the |
|
Uses this schema for class lookup. |
|
Specifies that the database syntax used is for the JDBC Thin driver. The database connection string must be of the form |
|
Displays the connection information. |
|
Shows the version. |
|
Uses |
|
Makes the connection listen for a debugger connection on the indicated port and host. The default value of host is |
Open a shell on the session namespace of the database orcl
on listener port 2481
on the host dbserver
, as follows:
ojvmjava -thin -user SCOTT@dbserver:2481:orcl
Password: password
The ojvmjava
tool commands span several different types of functionality, which are grouped as follows:
This section describes the options for the ojvmjava
tool command.
The ojvmjava Tool Output Redirection
You can direct any output generated by the ojvmjava
tool to a file by appending &>
filename
at the end of the command options. The following command directs all output to the listDir
file:
ls -lR &>/tmp/listDir
Scripting the ojvmjava Tool Commands in the @filename Option
This @
filename
option designates a script file that contains one or more ojvmjava
tool commands. The script file specified is located on the client. The ojvmjava
tool reads the file and runs all commands on the designated server. In addition, because the script file is run on the server, any interaction with the operating system in the script file, such as redirecting output to a file or running another script, will occur on the server. If you direct the ojvmjava
tool to run another script file, then this file must exist in $ORACLE_HOME
on the server.
Enter the ojvmjava
tool command followed by any options and any expected input arguments.
The script file contains the ojvmjava
tool command followed by options and input parameters. The input parameters can be passed to the ojvmjava
tool on the command line. The ojvmjava
tool processes all known options and passes on any other options and arguments to the script file.
To access arguments within the commands in the script file, use &1...&
n
to denote the arguments. If all input parameters are passed to a single command, then you can type &*
to denote that all input parameters are to be passed to this command.
The following shows the contents of the script file, execShell
:
chmod +x SCOTT nancy /alpha/beta/gamma chown SCOTT /alpha/beta/gamma java hello.World &*
Because only two input arguments are expected, you can implement the Java command input parameters, as follows:
java hello.World &1 &2
Note:
You can also supply arguments to the-command
option in the same manner. The following shows an example:
ojvmjava ... -command "cd &1" contexts
After processing all other options, the ojvmjava
tool passes contexts
as argument to the cd
command.
To run this file, do the following:
ojvmjava -user SCOTT -thin -database dbserver:2481:orcl \
@execShell alpha beta
Password: password
The ojvmjava
tool processes all options that it knows about and passes along any other input parameters to be used by the commands that exist within the script file. In this example, the parameters, alpha
and beta
, are passed to the java
command in the script file. The actual command is run as follows:
java hello.World alpha beta
You can add any comments in your script file using hash (#
). Comments are ignored by the ojvmjava
tool. For example:
#this whole line is ignored by ojvmjava
-runjava
This option controls whether or not the ojvmjava
tool shell command Java runs executable classes using the command-line interface or database resident classes. When the -runjava
option is present the command-line interface is used. Otherwise, the executable must be a database resident class that was previously loaded with the loadjava
tool. Using the optional argument server_file_system
means that the -classpath
terms are on the file system of the machine running Oracle server. Otherwise, they are interpreted as being on the file system of the machine running the ojvmjava
tool.
See Also:
"Using Command-Line Interface"-jdwp
This option specifies a debugger connection to listen for when the shell command java
is used to run an executable. This allows for debugging the executable. The arguments specify the port and host. The default value of the host argument is localhost.
These are used to execute a call to DBMS_DEBUG_JDWP.CONNECT_TCP
from the RDBMS session, in which the executable is run.
Running sess_sh Within Applications
You can run sess_sh
commands from within a Java or PL/SQL application using the following commands:
Application Type | Command and Description |
---|---|
PL/SQL applications |
dbms_namespace.shell(in command VARCHAR2)Your application can run individual commands on a unique session instance. The state of the shell is preserved between different calls of sess_sh within the same session. The following examples run the cd command of the sess_sh tool within a PL/SQL application:
dbms_namespace.shell('cd /webdomains'); dbms_namespace.shell('ls &> /tmp/test'); To reset the state of the shell instance, run the dbms_namespace.shell('exit'); |
Java applications | Instantiates oracle.aurora.namespace.shell.Shell within a Java server object. After creation, you must initialize the Shell object using its initialize method. Once initialized, you can run sess_sh commands, as follows:
String commands="cd /webdomains\nls -l"; StringReader commandReader = new StringReader(commands); Shell sh = new oracle.aurora.namespace.shell.Shell(); try { sh.initialize(); sh.invoke(new BufferedReader(commandReader), false); } catch (ToolsException te) { //Error executing the commands } |
This section describes the following commands available within the ojvmjava
shell:
Note:
An error is reported if you enter an unsupported command.Table 11-5 summarizes the commands that share one or more common options, which are summarized in Table 11-5:
Table 11-5 ojvmjava Command Common Options
Option | Description |
---|---|
|
Summarizes the operation of the tool. |
|
Summarizes the syntax of the tool. |
|
Shows the version. |
This command displays to stdout
exactly what is indicated. This is used mostly in script files.
The syntax is as follows:
echo [echo_string] [args]
echo_string
is a string that contains the text you want written to the screen during the shell script invocation and args
are input arguments from the user. For example, the following command displays out a notification:
echo "Adding an owner to the schema" &1
If the input argument is SCOTT
, then the output would be:
Adding an owner to the schema SCOTT
This command terminates ojvmjava
. The syntax is as follows:
exit
For example, to leave a shell, use the following command:
$ exit %
This command summarizes the syntax of the shell commands. You can also use the help command to summarize the options for a particular command. The syntax is as follows:
help [command]
This command is analogous to the JDK java
command. It calls the static main()
method of a class. It does this either by using the command-line interface or using a database resident class, depending on the setting of the runjava
mode. In the latter case, the class must have been previously loaded with the loadjava
tool. The command provides a convenient way to test Java code that runs in the database. In particular, the command catches exceptions and redirects the standard output and standard error of the class to the shell, which displays them as with any other command output. The destination of standard out and standard error for Java classes that run in the database is one or more database server process trace files, which are inconvenient and may require DBA
privileges to read.
See Also:
"Using Command-Line Interface"The syntax of the command with runjava
mode off
is:
java [-schema schema] class [arg1 ... argn]
The syntax of the command with runjava
mode on
is:
java [command-line options] class [arg1 ... argn]
where, command-line options can be any of those mentioned in Table 3-1.
Table 11-6 summarizes the arguments of this command.
Table 11-6 java Argument Summary
Argument | Description |
---|---|
|
Names the Java class schema object that is to be run. |
|
Names the schema containing the class to be run. The default is the invoker's schema. The schema name is case-sensitive. |
|
Arguments to the |
Consider the following Java file, World.java
:
package hello; public class World { public World() { super(); } public static void main(String[] argv) { System.out.println("Hello from Oracle Database"); if (argv.length != 0) System.out.println("You supplied " + argv.length + " arguments: "); for (int i = 0; i < argv.length; i++) System.out.println(" arg[" + i + "] : " + argv[i]); } }
You can compile, load, publish, and run the class, as follows:
% javac hello/World.java
% loadjava -r -user SCOTT@localhost:2481:orcl hello/World.class
Password: password
% ojvmjava -user SCOTT -database localhost:2481:orcl
Password: password
$ java hello.World alpha beta
Hello from Oracle Database
You supplied 2 arguments:
arg[0] : alpha
arg[1] : beta
This command shows the version of the ojvmjava
tool. You can also show the version of a specified command. The syntax of this command is:
version [options] [command]
For example, you can display the version of the shell, as follows:
$ version 1.0
This command displays the user name of the user who logged in to the current session. The syntax of the command is:
whoami
connect
This command enables the client to drop the current connection and connect to different databases without having to reinvoke the ojvmjava
tool with a different connection description.
The syntax of this command is:
connect [-service service] [-user user][-password password]
You can use this command as shown in the following examples:
connect -s thin@locahost:5521:orcl -u scott/tiger connect -s oci@locahost:5521:orcl -u scott -p tiger
Table 11-7 summarizes the arguments of this command.
Table 11-7 connect Argument Summary
Argument | Description |
---|---|
-service | -s |
Any valid JDBC driver URLS, namely, oci @<connection descriptor> and thin@<host:port:db> |
|
User to connect as |
-password | -p |
Password to connect with |
runjava
This command queries or modifies the runjava
mode. The runjav
a mode determines whether or not the java
command uses the command-line interface to run executables. The java
command:
Uses the command-like interface when runjava
mode is on
Uses database resident executables when runjava
mode is off
See Also:
"Using Command-Line Interface"Using the runjava
command with no arguments displays the current setting of runjava
mode.
Table 11-8 summarizes the arguments of this command.
Table 11-8 runjava Argument Summary
Argument | Description |
---|---|
|
Turns |
|
Turns |
|
Turns |
jdwp
This command queries or modifies whether and how a debugger connection is listened for when an executable is run by the Java command.
Note:
The RDBMS session, prior to starting the executable, executes aDBMS_DEBUG_JDWP.CONNECT_TCP
call with the specified port and host. This is called Listening.Using this command with no arguments displays the current setting.
Table 11-9 summarizes the arguments of this command.