Archived

This forum has been archived. Please start a new discussion on GitHub.

Environment variables for java IceBoxin IceGrid

I have java services running within IceBox. These services read system properties and act on it. I am on windoze !

When IceBox is started in standalone mode I pass the system properties either by setting them explicitly in the environment or via -D in the java command line.

I would like to deploy the same services running within java IceBox in IceGrid and need to pass the same system properties.

I have tried following and would appreciate your help / input to achieve the best solution.

Also, in the following cases ONLY case 3 works for me and values for environment variables are not set in case 1 and case 2. I really dont want to hard code the values in the xml file. (I have tried setting the system environment properties)

Thanks for your help in advance

Case 1
<icegrid>
    <application name="DevIceBox">
        <node name="localhost">
            <icebox id="DevIceBox" exe="java" activation="on-demand">
                [COLOR="Red"]<option>-DAPP_FILE=%APP_FILE%</option>
                <option>-DENV_FILE=%ENV_FILE%</option>[/COLOR]
                <option>IceBox.Server</option>
                <service name="MyService" entry="com.xxx.myservice">
                    <adapter name="${service}" endpoints="tcp -p 10010" register-process="true"/>
                </service>
            </icebox>
        </node>
    </application>
</icegrid>

Case 2
<icegrid>
    <application name="DevIceBox">
        <node name="localhost">
            <icebox id="DevIceBox" exe="java" activation="on-demand">
[COLOR="Red"]                <env>APP_FILE=%APP_FILE%</env>
                <env>ENV_FILE=%ENV_FILE%</env>[/COLOR]
                <option>IceBox.Server</option>
                <service name="MyService" entry="com.xxx.myservice">
                    <adapter name="${service}" endpoints="tcp -p 10010" register-process="true"/>
                </service>
            </icebox>
        </node>
    </application>
</icegrid>

Case 3
<icegrid>
    <application name="DevIceBox">
        <node name="localhost">
            <icebox id="DevIceBox" exe="java" activation="on-demand">
[COLOR="Red"]                <option>-DAPP_FILE=c:\config\config.xml</option>
                <option>-DENV_FILE=c:\config\dev.properties</option>[/COLOR]
                <option>IceBox.Server</option>
                <service name="MyService" entry="com.xxx.myservice">
                    <adapter name="${service}" endpoints="tcp -p 10010" register-process="true"/>
                </service>
            </icebox>
        </node>
    </application>
</icegrid>

Comments

  • benoit
    benoit Rennes, France
    Hi,

    Case 1 won't work, you can only reference environment variables from an environment variable definition.

    Case 2 should set the APP_FILE or ENV_FILE environment variables with the value of the %APP_FILE% or %ENV_FILE% environment variable (defined in the IceGrid node environment -- before the node is started) in the Java process environment. However, I don't think this will set any system properties. You should be able to access these environment variables with System.getenv() though (assuming you use JDK 1.5).

    Cheers,
    Benoit.
  • Benoit,

    Thanks for the reply.

    I have tried setting the environment variables in the script that launches icegridnode and also the system environments.

    In the java iceservice I am accessing these variables using System.getProperty( ) which returns null.

    Does it mean that when IceBox server instance is started the existing system properties are refreshed?
  • benoit
    benoit Rennes, France
    I don't think you can access environment variables through system properties with System.getProperty() (unless of course you explicitely specify a -D<name>=<value> option for each environment variable). You have to use System.getenv() to get the value of an environment variable but this method is only available in the JDK >= 1.5.

    Note that another mechanism to pass environment specific configuration to the servers started by an IceGrid node is to use the IceGrid node "IceGrid.Node.PropertiesOverride" configuration property. This property allows you to specify Ice properties that will be passed to each server started by the IceGrid node.

    Cheers,
    Benoit.
  • Thanks for your help.

    I will work on your suggestions.

    Regards