1.7.1 Starting the OPG4J Shell
Launching the OPG4J Shell
The Java shell executables are found in
/opt/oracle/graph/bin
after the graph server (PGX)
installation, and in <CLIENT_INSTALL_DIR>/bin
after the Java
client installation.
The OPG4J shell uses JShell, which means the shell needs to run on Java 11 or later. See Installing the Java Client for more details on the prerequisites. You can then launch the OPG4J shell by entering the following in your terminal:
cd /opt/oracle/graph
./bin/opg4j
When the shell has started, the following command line prompt appears:
For an introduction type: /help intro
Oracle Graph Server Shell 21.4.0
Variables instance, session, and analyst ready to use.
opg4j>
By default, the OPG4J shell creates a local PGX instance, to run graph functions in the same JVM as the shell as described in Developing Applications Using Graph Server Functionality as a Library.
Command-line Options
To view the list of available command-line options, add
--help
to the opg4j
command:
./bin/opg4j --help
To start the opg4j shell without
connecting to the graph server (PGX), use the --no_connect
option
as shown:
./bin/opg4j --no_connect
Starting the OPG4J Shell on Remote Mode
The OPG4J shell can connect to a graph server (PGX) instance that is running on another JVM (possibly on a different machine). In order to launch the OPG4J shell in remote mode, you must specify the--base_url
parameter as
shown:./bin/opg4j --base_url https://<host>:7007 --username <graphuser>
<host>
: is the server host<graphuser>
: is the database userYou will be prompted for the database password.
Note:
The graph server (PGX), listens on port7007
by default. If needed, you can
configure the graph server to listen on a different port by changing the port value
in the server configuration file (server.conf
). See Configuring the In-Memory Graph Server (PGX) for details.
When the shell has started, the following command line prompt appears:
Oracle Graph Server Shell 21.4.0
Variables instance, session, and analyst ready to use.
opg4j>
If you have multiple versions of Java installed, you can easily switch between installations by setting the JAVA_HOME variable before starting the shell. For example:
export JAVA_HOME=/usr/lib/jvm/java-11-oracle
Batch Execution of Scripts
The OPG4J shell can execute a script
by passing the path(s) to the script(s) to the opg4j
command. For example:
./bin/opg4j /path/to/script.jsh
Predefined Functions
The OPG4J shell provides the following utility functions:
println(String)
: A shorthand for System.out.println(String).loglevel(String loggerName, String levelName)
: A convenient function to set the loglevel.
The loglevel
function allows you to set the log level
for a logger. For example, loglevel("ROOT", "INFO")
sets the level
of the root logger to INFO
. This causes all logs of
INFO
and higher (WARN
, ERROR
,
FATAL
) to be printed to the console.
Script Arguments
You can also provide parameters to the script. For example:
./bin/opg4j /path/to/script.jsh script-arg-1 script-arg-2
In this example, the script /path/to/script.jsh
can
access the arguments via the scriptArgs
system property. For
example:
println(System.getProperty("scriptArgs"))// Prints: script-arg-1 script-arg-2
Staying in Interactive Mode
By default, the OPG4J shell exits after
it finishes execution. To stay in interactive mode after the script finishes
successfully, pass the --keep_running
flag to the shell.
For example:
./bin/opg4j -b https://myserver.com:7007/ /path/to/script.jsh --keep_running
Parent topic: Interactive Graph Shell CLIs