JDA WMS — How to set/get Environment Variables

An environment variable’s value can either be set from the MOCA Registry or the Operating System. When MOCA Server is started, these variables are loaded into the MOCA Server and can be used at any point while the Application is running.

But why do we need environment variables?

Well, for the most part, the application utilizes these environment variables based on the MOCA Server’s internal processes itself or the programming logic of the application. The MTF MOCA Task utilizes Java, for example, if it is unable to find the path to java.exe, it will fail to initialize. Another example would be that if you want to build/compile a Java code using Apache Ant, but you are unable to call the “ant’s” executable file if ANT_HOME is not set; your code wouldn’t build. Another example would be if you want to define a mail server’s hostname or the machine’s hostname through which a code will utilize that variable when a job executes.

Some other environment variables may not depend entirely on the initializing and running of the MOCA Server but are still useful to make our lives easy like the PATH variable. If the PATH variable isn’t set correctly or missing some parameters like %MOCA%\bin (or $MOCA\bin in Linux) for instance, you will not be able to use a lot of utilities from the command line and will have to call that process directly from the directory path from where it is located and then there will always be the possibility that it may not run in its desired way.

I’m sure the question arises in your mind of when to decide if a variable should be set in MOCA Registry and when it should be set it in the OS?

The answer is simple — “it depends on the scope of the variable you are defining”. If it needs to be defined on an Application level — to be used inside that instance or if the variable is specific to that instance only, then you should set it in MOCA Registry.

On the other hand, if there are multiple JDA WMS instances hosted on the same Physical Server or VM — then it is best to set it up on the OS level, so it is accessible to all instances (if that is the requirement, of course).

How do I see what environment variables are set? How do I fetch that data? You can use the following command to accomplish it from Oracular MOCA Client:

Windows App Server:
execute os command where cmd = 'set'
----OR----
RHEL (Linux):
execute os command where cmd = 'printenv'

On Windows Server:

JDA WMS App Server hosted on Windows Server 201x

On Linux:

JDA WMS App Server hosted on RHEL

For Testing, I will create a new variable called ALI_VAR having the value of testvalue and we’ll show this variable from Oracular MOCA Client.

Environment Variable ALI_VAR set.

Please note that whether you set environment variables from MOCA Registry or the OS, you’ll need to restart MOCA Server so the changes are visible from JDA WMS.

We can now see that the environment variable is visible through MOCA Client

Now let’s say I have added the same variable with a different value from MOCA Registry and we’ll see if it overrides or not?

Added a variable in MOCA Registry

The screenshot below confirms that MOCA Registry overrides the environment variable that is defined both in the OS and in MOCA Registry.

ALI_VAR changed

You can also use Groovy to find environment variables using MOCA Client.

[[
value = moca.getRegistryValue('environment.lesdir');
]]
Using Groovy to find Environment Variables

Note: MOCA_ENVNAME and MOCA_REGISTRY environment variables are not set in the MOCA’s registry, but rather in the rptab file. This can be determined by using the following commands:

execute os command where cmd = 'echo %MOCA_ENVNAME%'
&
execute os command where cmd = 'echo %MOCA_REGISTRY%'
----OR----
publish data where x = @@MOCA_ENVNAME
&
publish data where x = @@MOCA_REGISTRY

Using Windows Server’s set command:

using Windows’s set command

Using echo:

using echo %variable%

Using publish data:

@@ Denotes an Environment Variable

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store