All the little references when you copy an eclipse project

Okay, maybe I’m not supposed to copy eclipse projects this way, but I simply wanted to make a copy of an eclipse project that had already been appropriately configured to include a number of libraries, etc., so that I didn’t have to go through all that config again. Seems like it should work, intuitively, and I guess we’re close, but there were a few tweaks I had to make by hand to get everything up and running the way I wanted.Brief overview of my eclipse environment and project:

  • I am running eclipse V3.4.2 with WTP (and a couple other plugins that are inconsequential)
  • I’ve configured a Tomcat server so that I can run from within eclipse – i.e. Run As…->Run on Server
  • My project is a Dynamic Web Project

First thing I do after copying the project from, say, “MyProject” to “MyProject2” is right click on the project, select Properties, go to Web Project Settings and update the Context Root; I want my new service to run at the URL …/services/MyProject2 instead of …/services/MyProject so I set the context root to MyProject2. I do a Project->Clean and then build the project and all looks fine. When I right-click Run As->Run on Server, select my Tomcat Server, click Next, here is the rub: Instead of showing MyProject2 in the list of configured projects I see MyProject listed twice. Turns out that I can select one of them and click the Remove All button, continue with the deployment (even with the old project name there) and everything runs on Tomcat as you would expect – the server responds to requests at url …/services/MyProject2.So the question is, why isn’t the new project name picked up in the right places? I believe it is because a key settings file is written at project creation time via the wtp plugins, and writes the project name into that file, but when I created the project via a copy of the old, eclipse does not update that file. I found the file, but try as I might I cannot find a config page anywhere that allows me to update it – I guess this is not too surprising as, in theory, this is just bound to the eclipse project name and it would be confusing for users to diverge from that naming convention (certainly is confusing me).The solution:The file is the org.eclipse.wst.common.component file that is in the //.settings directory. Close eclipse, open that file (it’s an XML file) and update the line that reads:<wb-module deploy-name="MyProject">to<wb-module deploy-name="MyProject2">and start eclipse. At this point I had to do another Project->Clean and build (else the context root for the web project was a mess) and then the last thing you need to do is clean the Tomcat work directory by right clicking on the server in the “Servers” tab and selecting Clean Tomcat Work Directory… Now, try running the app again via Run As->Run on Server and when you’ve selected the server and clicked Next you will see both MyProject and MyProject2 in the Configured Projects list – not to worry, the MyProject is just a left over reference from the last time you ran the old project and can be removed by selecting and clicking Remove All.And now you’ve managed to update what I believe is the last reference to the old project name from your new project.

Share Your Thoughts