6

In a Spring file I have:

 <bean id="propertyConfigurer" class="org.myapp.MyConfigurator"> <property name="locations"> <list> <value>classpath:configuration-${env}.properties</value> </list> </property> </bean> 

the ${env} variable is defined in maven's profile. But when I run from eclipse the application in tomcat 6 (published) it doesn't look in maven. So how can I set the variable for Tomcat?

Thanks

Randomize

1

3 Answers 3

6

Add system variable in Eclipse: Go to Run --> Run Configurations --> Tomcat Select Arguments tab and add to VM arguments -Denv=blabla

Sign up to request clarification or add additional context in comments.

Comments

5

To define a variable in in the tomcat context.xml that can be used in spring add this line to the right context in context.xml.

<Parameter name="env" value="ABCDEFG" override="false"/> 

1 Comment

override: Set this to false if you do not want a <context-param> for the same parameter name, found in the web application deployment descriptor, to override the value specified here. By default, overrides are allowed.
3

Tarlog solution can be solve your problem but only inside eclipse, if you remove your server definition from eclipse you lost the definition and you need to add it again each time you change your IDE or delete the server definition.

So better way create a shell or bat file(like runServer.sh/.bat) according to your environment and add this parameter to the JAVA_OPTS variable so this variable called when catalina.sh/.bat is running (startup.sh/.bat called catalina script inside it). You can use this approach at your local, test and prod environment.

Windows: runServer.bat

set JAVA_OPTS="-Dvariable=value" tomcat/bin/startup.bat 

Linux: runServer.sh

export JAVA_OPTS="-Dvariable=value" tomcat/bin/startup.sh 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.