Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

how to pass command line arguments to Jetty

HI,
I am starting jetty like : service jetty start
This links to the jetty.sh file...
Now in my java code i have the following lines :
<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:properties/${FLOCK_APPS_CONFIG}/log4j.properties</param-value>
    </context-param>

<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>classpath:properties/${FLOCK_APPS_CONFIG}/database.properties</value>
        </property>
    </bean>

Open in new window


If i make an environment variable with name FLOCK_APPS_CONFIG it works.
But i dont want to make an environment variable. I want to use another approach
in which some way i pass this parameter while starting jetty.
How can i do this ?

Thanks
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not then something like this?

export FLOCK_APPS_CONFIG=foo;service jetty start

Open in new window

Avatar of Rohit Bajaj

ASKER

i will be running the service from a headless user in linux. it wont have any environment variablea no bash profile. so i guesa i cannot do that
i can have the parameter also in a file. but the problem is how does spring pick it up at runtime. as based on this parameter i will pick up correct configuration file.
it wont have any environment variablea no bash profile. so i guesa i cannot do that
You (almost certainly) guess wrong
Hi,
That didnt work even for a normal user i tried : export FLOCK_APPS_CONFIG=staging;service jetty start
But i got the following error in jetty logs :
IllegalArgumentException: Could not resolve placeholder `FLOCK_APPS_CONFIG` in string value "classpath:properties/${FLOCK_APPS_CONFIG}/log4j.properties
For the normal user also it works only when i put export FLOCK_APPS_CONFIG=staging in ~/.bash_profile
As what user is jetty running?
i am logged in as root.its running as root only
i have read about parameters passing with -D option. dont know much but if there is some way to pass it inside jetty.sh script file which is inside of bin ...probably things will work
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial