Passing parameters in embedded Jetty spring project

I have a spring mvc project and i am starting it using embedded jetty  like :
package org.directi.code;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.springframework.web.servlet.DispatcherServlet;

public class AppStart {

    private static final Logger logger = Logger.getLogger(AppStart.class);

    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        WebAppContext context = new WebAppContext();
        context.setResourceBase(new ClassPathResource("webapp").getURI().toString());
        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "", "");
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            public void run() {
      "Trying to shutdown flock To Dos app service cleanly");


Open in new window

In my web.xml i have a following line :

Open in new window

where in root-context.xml has a line :

Open in new window

I am unable to find any way to pass the FLOCK_APPS_CONFIG parameter in the main file so that it can be
accessed inside root-context.xml
How do i pass this from the main java file where jetty is embedded ?

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.

Why do you need to do that? I don't think you can pass the parameters dynamically to the root-context.xml. You will need to define the full path to the
Amitkumar PSr. ConsultantCommented:
Step 1:
Give it a try by adding below in main() method of your program.
System.setProperty("FLOCK_APPS_CONFIG", "staging");


Set it as VM arguments (-DFLOCK_APPS_CONFIG=staging) while launching AppStart program.

Step 2: (If not able to pick after step1) Change config to read file from absolute path, not using classpath


I assume that properties folder is residing under WEB-INF folder (if you application is a web application)

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
Amitkumar PSr. ConsultantCommented:
Refer below link how to set VM arguments in Eclipse, if you are using Eclipse.
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

From novice to tech pro — start learning today.