Eric
Eric

Reputation: 41

How remove context path in java application

I want to remove context path from my url. when i run project its run in http:///localhost:8080/myApp/. i want to remove myApp from it. all my config based on java. i change context.xml to this <Context antiJARLocking="true" path="/"/> but when i want to login that based on spring security not working. I also add web.xml based java config like this.

     public class AppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws   ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher =   servletContext.addServlet("DispatcherServlet", new   DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
  }

private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("mypac.config");
    return context;
 }
}

Upvotes: 1

Views: 5118

Answers (2)

If you're using Eclipse ide:

  1. Right click your project, choose Properties->Web Project Settings-> in Context root, change yourApp to / and click OK.
  2. In Servers Explorer, remove yourApp from Tomcat Server.
  3. (Option) If you use Maven, right click your project -> choose Maven -> choose Update Project.
  4. Rerun your project.

Upvotes: 1

Ataur Rahman Munna
Ataur Rahman Munna

Reputation: 3917

For tomcat server, you can delete your existing ROOT/ directory. Rename your war as ROOT.war and deploy it.

Configure the context root in tomcat's conf/server.xml to use your war file (assuming my_war is your war name)

< Context path="" docBase="my_war" reloadable="true">

you can follow the link also that already answered.

Upvotes: 1

Related Questions