Search code examples
javalinuxtomcatenvironment-variablesproduction-environment

how to setup environment variable CA_DATA in tomcat config


I am trying to implement & access a native API(.so) in my java web project which look for CA_DATA variable.

 set it in .bashrc as -
export CA_DATA=/app/IstCorrectAddress/Data;

i can see this in path when echo but problem is when .war deployed on tomcat server cant see the variable.

I want to set this environment variable somewhere in tomcat config which can be seen by war on startup. please suggest where and how to set it so that it can access.

Please suggest.


Solution

  • Looks like your using JNI(java native Interface here). If you want to add libraries to tomcat, the way I do is to set it up in setevn.sh or setenv.sh, depends on which environment you are in

    In this file, you will have this

    set CATALINA_OPTS=%CATALINA_OPTS% /<path to proerties>/xyz.so
    

    In catalina.bat, I would have these lines

    rem Get standard environment variables
    if "%CATALINA_BASE%" == "" goto gotSetenvHome
    if exist "%CATALINA_BASE%\bin\setenv.bat" call "%CATALINA_BASE%\bin\setenv.bat"
    goto gotSetenvBase
    :gotSetenvHome
    if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
    :gotSetenvBase
    

    You can set the path in profile.bash. Hope this helps.