2

I have to set an environment variable separated by dot in my tomcat startup script. For example

host.name=localhost

I know shell doesn't accept dot separated variables. Is there a work around ?

I found somewhere that we can use env variable but that doesnt seem to work. I used

env host.name=localhost

Can anyone help me please ?

2 Answers 2

3

Thanks a lot for your reply AB. However i found a much better solution. I simply added in the CATALINA_OPTS variable of tomcat in the file /usr/share/tomcat7/bin/setenv.sh:

export CATALINA_OPTS="-Dhost.name=localhost"

This worked exactly as I wanted.

2

I do not understand why that is required for Tomcat. All configuratios are in eg: /etc/tomcat7/server.xml. I have worked for several years with Tomcat, but this kind of configuration I've never needed. Anyway here is your answer.

TL;DR

env "host.name=localhost"

Test with:

env "host.name=localhost" perl -le 'print $ENV{"host.name"}'

or with Java:

Create a runnable jar

package stackoverflow;

import java.util.Map;

public class PrintEnv {
    public static void main(String[] args) {
        Map<String, String> env = System.getenv();
        for (String envName : env.keySet()) {
            System.out.println(envName + ": " + env.get(envName));
        }
    }
}

and test with:

env "host.name=localhost" java -jar PrintEnv.jar | grep host.name
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.