Passing parameters in embedded Jetty spring project

HI,
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.core.io.ClassPathResource;
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.setDescriptor("webapp/WEB-INF/web.xml");
        context.setResourceBase(new ClassPathResource("webapp").getURI().toString());
        context.setAttribute("FLOCK_APPS_CONFIG","staging");
        context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",".*/[^/]*jstl.*\\.jar$");
        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);
        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration");
        server.setHandler(context);
        server.start();
        server.join();
        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
            @Override
            public void run() {
                logger.info("Trying to shutdown flock To Dos app service cleanly");
            }
        }));

    }
}

Open in new window


In my web.xml i have a following line :
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/root-context.xml</param-value>
    </context-param>

Open in new window


where in root-context.xml has a line :
 <context:property-placeholder
            location="classpath:properties/${FLOCK_APPS_CONFIG}/database.properties"
            ignore-unresolvable="true"/>

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 ?

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.

girionisCommented:
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 database.properties.
0
Amitkumar PSr. ConsultantCommented:
Step 1:
Give it a try by adding below in main() method of your program.
System.setProperty("FLOCK_APPS_CONFIG", "staging");

OR

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

 <context:property-placeholder
            location="/WEB-INF/properties/${FLOCK_APPS_CONFIG}/database.properties"
            ignore-unresolvable="true"/>

I assume that properties folder is residing under WEB-INF folder (if you application is a web application)
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
Amitkumar PSr. ConsultantCommented:
Refer below link how to set VM arguments in Eclipse, if you are using Eclipse.

http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Flaunchers%2Farguments.htm
0
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

From novice to tech pro — start learning today.