Ryan S
Ryan S

Reputation: 3268

Tomcat Environment Variables - Is it possible to make them permanent? or not lost on re-deployment?

I am working on an application which uses Tomcat Environment Variables (which are created through the admin console). With my little experience with this I have realized that these are lost when the application is un-deployed and re-deployed again.

I would like to either keep them there, or create them automatically upon deployment.

Is it possible? Since it is cumbersome to re-create the environment variables each time I re-deploy.

I am using Tomcat 7.0.

Upvotes: 2

Views: 1408

Answers (1)

phatfingers
phatfingers

Reputation: 10250

Yes, it's possible. You register your variables in server.xml, and each application context can choose to reference any of them to make them available in JNDI.

server.xml

<GlobalNamingResources>
    <Environment name="example" value="prod" type="java.lang.String" override="false" /> 
</GlobalNamingResources>

context.xml

<ResourceLink name="example" global="example" type="java.lang.String" />

code.java

String example = (String) (new InitialContext()).lookup("java:comp/env/example");

Upvotes: 2

Related Questions