10 November 2006

How to Set Java Options For OC4J

OC4J runs in two different environments -- OC4J standalone and Oracle Application Server -- it's the same OC4J, but how it's started is different.

Setting Java properties for the OC4J instance is therefore done in a slightly different way.

1. An OC4J standalone environment is created by extracting the contents of the oc4j_extended.zip file. This gives you an simple yet complete OC4J environment.

To start OC4J standalone, you call the Java executable yourself and run the oc4j.jar file.

Thus in this sort of environment, you provide the Java properties (-X, -D) on the command line

>java -Xmx256m -Ddebug.log=true -jar oc4j.jar

2. In an Oracle Application Server environment, an OC4J instance is launched (and monitored/stopped) by the OPMN service.

The OPMN service reads a configuration file $ORACLE_HOME/opmn/conf/opmn.xml that defines what processes OPMN needs to start, and also what environment needs to be supplied to the process.

The Java properties for an OC4J instance are defined within its start-parameters/java-options tag in its opmn.xml definition.
<process-type id="admin" module-id="OC4J" status="enabled">
<category id="start-parameters">
<data id="java-options"
value="-Xrs -server -XX:MaxPermSize=128M
-ms512M -mx1024M -XX:AppendRatio=3
<category id="stop-parameters">
<data id="java-options"
value="-Djava.awt.headless=true -Dhttp.webdir.enable=false"/>
<start timeout="600" retry="2"/>
<stop timeout="120"/>
<restart timeout="720" retry="2"/>
<port id="default-web-site" range="12501-12600" protocol="ajp"/>
<port id="rmi" range="12401-12500"/>
<port id="rmis" range="12701-12800"/>
<port id="jms" range="12601-12700"/>
<process-set id="default_group" numprocs="1"/>
To add extra Java options, this opmn.xml file can be modified to set the additional property values required. Don't forget to take a backup first.

Once you change the file, execute the command below to request OPMN to reload the configuration file into memory:

>$ORACLE_HOME/opmn/bin/opmnctl reload

and then start the OC4J instance.

As of the Oracle Application Server 10g R3 ( release, the Java options for an Oc4J instance can be set directly from Application Server Control console.

No need to manually edit the opmn.xml file.

The Start Parameters:Java Options settings can be accessed using the Server Properties page of the OC4J instance you wish to configure.


Anonymous said...

Hi, I'm wondering if there is any way of setting these start-parameters in case 2) from a shell script? Do you really have to go into the opmn.xml-file and manually add the parameters?

Anonymous said...

What happens when I start oc4j following way
java -Xmx256m -Ddebug.log=true -Ddebug.log=false -jar oc4j.jar
Can I get debugging error messages in log?

Buttso said...

For case 2, the opmn.xml file is the single point source of information for how the OC4J instance will be started. I don't know of a way to modify them easily using a shell script.

One option that is non trivial but which would be possible is to use the OPMN MBeans that are available. The OPMN MBeans expose the current settings in the opmn.xml file and provide operations to add/edit/remove settings.

There's no out of the box JMX command line client, but you could look to write something yourself, then call that to effect the changes using the MBeans.

The OPMN MBeans can be seen from the Cluster MBean Browser tree within the ASC management console.

Buttso said...

What happens when I start oc4j following way
java -Xmx256m -Ddebug.log=true -Ddebug.log=false -jar oc4j.jar
Can I get debugging error messages in log?

The easy answer is yes. OC4J itself uses the Java Logging API and is configured by default so that all the log messages are directed into a file set. Look in the j2ee/home/config/j2ee-logging.xml file for the logger names and levels. These can also be set using the ASC console in the 10.1.3 release.

If you have an application that uses Jakarta Commons Logging, Log4j, or the Java Logging API, then you can configure those frameworks to direct their logging messages to files using the mechanisms they provide.

If simply you want to redirect stdout/stderr to a log file then you can use the OC4J configuration parameters:

java -jar oc4.jar -err [file] -out [file]

Levangie said...

I am looking to push stdout/sterr into the log file, so your the last line of your last comment intrigues me. Should this line go in the ompn.xml as part of the java option?

Thanks in advance.

Anonymous said...


I want to set java options for 0c4j standalone standalone server(Developer's version which does't have EM and opmn.xml with it). How can i set java options for this?

Thanks in advance

Buttso said...

If you are using standalone, then you are in complete control over how it is launched. If you wish to set Java properties such as heapsize, etc. or other forms of System properties, then just use the standard Java mechanism when starting OC4J:

java -Xmx256m -Dmy.prop=hello -jar

If you have a long set of commands or want to save typing, put these into a batch/shell script and use that to launch OC4J.

Anonymous said...

Can this be dome from groovy with OC4JClient?