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
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Why not then something like this?

export FLOCK_APPS_CONFIG=foo;service jetty start

Open in new window

0
Rohit BajajAuthor Commented:
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
0
Rohit BajajAuthor Commented:
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.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

CEHJCommented:
it wont have any environment variablea no bash profile. so i guesa i cannot do that
You (almost certainly) guess wrong
0
Rohit BajajAuthor Commented:
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
0
Rohit BajajAuthor Commented:
For the normal user also it works only when i put export FLOCK_APPS_CONFIG=staging in ~/.bash_profile
0
CEHJCommented:
As what user is jetty running?
0
Rohit BajajAuthor Commented:
i am logged in as root.its running as root only
0
Rohit BajajAuthor Commented:
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
0
CEHJCommented:
It's NOT a good idea to run it as root. This reference looks sensible, though with user 'jetty' deliberately not having a shell, you will have to put the variable somehow in a script

http://www.eclipse.org/jetty/documentation/current/startup-unix-service.html

Of course there's a difference between an environment variable and a -D jvm property, but your original code could possibly work with the latter
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.