151

This is the error that I got when I created my first Axis2 web service using Eclipse. After I wrote the class, I created the web service with Apache Axis2. When I click the start server button in eclipse it gives an error message:

Could not publish server configuration for Tomcat v6.0 Server at localhost.
Multiple contexts have a path of "/FirstApache".

FirstApache is the dynamic web project that I created before. I selected the correct web project from the configuration part in the web service wizard.

How can I fix this?

Alex Ciminian
  • 11,398
  • 15
  • 60
  • 94
kkk
  • 1,551
  • 2
  • 10
  • 9
  • Easier answer is to right click on server tab, go to add and remove, and only have the project you want in the configured tab – TanDev Nov 29 '20 at 06:28

24 Answers24

306

Search for the server.xml file and check your <Context> tags, probably there are multiple definitions for the same path. Remove the duplicates and it should work for you.

Check out the answer here.

Auto-format the xml file (control + shift + f) since the second <Context> tag may be on the same line, but outside the viewport and really far away from the visible one.

Alex Ciminian
  • 11,398
  • 15
  • 60
  • 94
  • 14
    You can find the server.xml file in workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf (change tmp0 in case this is not your eclipse default server) – Repoker Sep 30 '13 at 09:23
  • I got this problem after I created a copy of a dynamic web project in eclipse java ee and tried to run the JSP's in the copy instead. How do I fix this problem ? – Erran Morad May 06 '14 at 21:10
  • Should be protected to avoid other useless "thanks". An up vote to the answer is better than a thanks comment. – Dwhitz May 17 '17 at 14:52
  • Thanks,it's working, but I am in confusion why this duplication occurs? – Sandip S. Oct 09 '17 at 11:21
  • This solution still works, I'm using Tomcat 8.5 on Eclipse V2018-12 – Raymund Arthur Feb 27 '19 at 07:30
  • More than one apache tomcat set up in your server set up can also cause this. I just removed the previous copy, which wasn't used, and it ifixed it. – Smart Coder Apr 21 '20 at 15:06
79

In STS/Eclipse go to "project explorer" or "package explorer" and there is a folder called "server." Open it and you will find server.xml file. Inside this file at the bottom you find a definition like

<Context docBase="myproject" path="/myproject" reloadable="true"
   source="org.eclipse.jst.jee.server:myproject"/>

You might find duplicates of the same definition that you would need to remove.

ElGavilan
  • 6,610
  • 16
  • 27
  • 36
Develop4Life
  • 7,581
  • 8
  • 58
  • 76
  • 1
    Adding deleting of servers added ,this line one more time automatically – Vinayak Shedgeri Oct 05 '16 at 03:36
  • If the app does not start even after this, go to the "Servers" tab next to Console and remove all the modules located inside the dropdown of server name. Rerun the project after this – sss Jan 22 '19 at 00:24
45

In Eclipse, go to the Servers project. Open the tree for the Tomcat version you are using. Open file server.xml and verify your Context tags.

biegleux
  • 13,179
  • 11
  • 45
  • 52
35

In your eclipse IDE on project explorer acess the server.xml like in:

enter image description here

And remove context tags with duplicates references for your project:

enter image description here

Fernando Nogueira
  • 1,302
  • 1
  • 14
  • 22
17

Go to server.xml and Search for "Context" tag with a property name "docBase".

Remove the duplicate lines here. Then try to restart the server.

Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76
13

Go to the Servers project in eclipse, under your runtime server configuration(in my case Tomcat v7.0 Server at localhost-config) go to server.xml file then search for <context> tag, normally you will find more than one context tag, delete them and run your application in the appropriate server that will work now.

in my case i have found duplicate Context tag :

<Context docBase="my-project" path="/my-project" reloadable="true" source="org.eclipse.jst.jee.server:my-project"/&gt;&lt;Context docBase="my-project" path="/smartphone-selfcare" reloadable="true" source="org.eclipse.jst.jee.server:my-project"/></Host>
Majid Laissi
  • 19,188
  • 19
  • 68
  • 105
sofiene zaghdoudi
  • 3,108
  • 2
  • 17
  • 11
11

In eclipse using tomcat you just open this server.xml file and find Context tag and here you see your context name is more then one you just delete useless contexts and restart your server it will working....

enter image description here

Zeeshan Akhter
  • 1,881
  • 20
  • 19
6
  1. In your project's Properties, choose "Web Project Settings".
  2. Change "Context root".
  3. Clean your server
  4. now you can restart your server
Fakher
  • 2,098
  • 3
  • 29
  • 45
  • Excellent solution for devs using more than one instance of the same application in different locations on their workstations. I've found that not all installations of Eclipse/Tomcat have a tag in their server.xml file. – Mindsect Team Aug 08 '17 at 16:20
6

Eclipse >> project explorer >> servers >> server.xml >> tag >> remove duplicate tag of your project

2

Try to delete the existing tomcat server in the server console. If you don't have the console then you can go to "Show view ->server", delete the server by right clicking on it, then add a new server.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
2

If you are using Tomcat 7 and Eclipse, click on the Tomcat server and then goto the modules tab. There you will find the duplicate entry. Remove both the entry and redeploy the application. You are good to go now.

SamDJava
  • 267
  • 3
  • 13
2

On a related note, if you have copied a project or in anycase, have the same context path for 2 'active' projects, you have to change the context path of one of them, then clean the tomcat server settings, then republish the servers

see this in-more detailed answer

Community
  • 1
  • 1
penguinsource
  • 1,120
  • 3
  • 16
  • 40
2

Simply remove the server in Eclipse and add tomcat server again. than shutdown the tomcat in tomcat/bin/shutdown.bat file and start the server in eclipse.

Phoenix
  • 1,470
  • 17
  • 23
1

I had that problem before. I just solved it by expanding the tomcat tree and delete the folder that is causing the clash. in your case is /FirstApache. after you delete it. then you rerun it, you should be able to run. If it happens again, delete it and try again.

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
aPEARR
  • 53
  • 1
  • 10
1

This error occurs when you copy a project than past it, and then you change the name of that project.

in such a case, follow the following steps.

Step-1: you need to edit your web.xml file. remove servlet and servlet-mapping of the previous projects.

Step-2: got to SERVER--> server.xml--> find context

Example :- Context docBase="JSPandServletDemo" path="/JSPandServletDemo" reloadable="true" source="org.eclipse.jst.jee.server:JSPandServletDemo"/>

now you just need to change the pathname to your current project name.

Good Luck Happy Coding :)

Akib Sayyed
  • 89
  • 1
  • 3
0

Remove the space or empty line in server.xml or context.xml at the beginning of your code

0

In my case I found duplicate paths in Servers/Tomcat5.5 at localhost-config/server.xml under tag. Removing the duplicates solved the problem.

MoneeK
  • 25
  • 6
0

Delete org.eclipse.wst.server.core and org.eclipse.wst.server.ui from .metadata/.plugins of wrokspace

delete the server from eclipse then reconfig the server in eclipse.

Vivek Kamble
  • 106
  • 2
  • 7
0

Go to servers Click right at Tomcat click at Add and remove then click at remove all

Amine Ouadrani
  • 301
  • 2
  • 7
0

It is pretty easy to do for me. If you created the server and you know the path of the directory where the server files are located then one can simply open the server.xml file which is right inside the server's folder.

Just edit the file to remove repeated <Context...> tag for the specific project which on running threw the error previously.

ldev
  • 103
  • 1
  • 6
0
  • In Eclipse, in Servers, expand Apache Tomcat
  • Delete all the "Contexts"
Ashish Augustine
  • 1,784
  • 4
  • 20
  • 50
0

In Eclipse

  1. Right click on the project
  2. click on properties and it opens the properties window
  3. select web project settings from the properties window
  4. change the context root

enter image description here

abdella
  • 490
  • 5
  • 11
-1

If you are using STS and your server is Pivotal Just double click on the server and go to >Modules tab >display Configure the Web Modules on this server.>you can just remove modules and run once again.

Ganesh Giri
  • 1,135
  • 11
  • 18
-1
 //Trying to do more than one thing to the object in the same context, 
//the solution is to work on single context objects

public class SingletonContext<TContext>
    where TContext: DbContext,new()
{
    private static TContext _context;

    private SingletonContext()
    {

    }
    public static TContext GetInstance()
    {
        if (_context == null)
        {
            _context = new TContext();
        }
        return _context;
    }

}
Tugay ÜNER
  • 177
  • 1
  • 5