5

I have recently upgraded a framework I am developing with and one of the jars from the old install has been upgraded to a newer version (i.e. the name of the jar is different).

All of the (200+) projects in my workspace depend on this jar and so now are displaying the following two errors:

  1. "Project 'Blah' is missing required library"
  2. "The project cannot be build until build path errors are resolved"

It will take me a substantial amount of time to modify the build path of every project in my workspace, firstly removing the incorrect jar and then adding the new one.

Is there a way to add/remove a jar to all (or a group of) projects in one go?

This question illustrates adding jars using libraries - something I could use going forward but doesn't fix my current problem.

I am running Eclipse Mars 4.5.0

Community
  • 1
  • 1
ferekdoley
  • 139
  • 1
  • 8
  • Tried this ? `Window - Preferences - Java - Build Path - User Libraries` – Lucky Sep 29 '15 at 11:24
  • 1
    @Lucky that would solve the *add* problem, but OP would still have to remove the old jar from all the projects – Cinnam Sep 29 '15 at 11:32
  • @Lucky - Cinnam is right. I need to remove the old reference. Even if I did create a new user library I don't know if there is a way to add that library to all existing projects in one go. Is there? – ferekdoley Sep 29 '15 at 11:52
  • @ferekdoley I haven't tried that, but I'm guessing you could always edit the JRE definition (as described in the accepted answer in your link). That should work for all projects that use that JRE, although it might not be the cleanest solution. – Cinnam Sep 29 '15 at 12:06
  • @Cinnam - Yeah, I am a little reluctant to modify the JRE definition as seems a little hacky. For future projects I'll go with User Libraries to avoid the same issue down the line. – ferekdoley Sep 29 '15 at 12:11

2 Answers2

4

On the back of Chandrayya G K's answer I have found a simple solution to solve my issue that doesn't involve creating extra projects etc. - Simply find and replace the reference to the jar in the classpath.

Within eclipse press Ctrl+H to bring up the Search Window.

enter image description here

Click File Search Tab

In the "Containing text:" field enter the classpathentry tag that references the old jar. This can be found in the .classpath file within any of your eclipse projects. Mine looks like this:

<classpathentry kind="lib" path="C:/myjars/old-jar.jar"/>

You can then specify .classpath in "File name patterns" field to limit your search to the classpath files.

Restrict "Scope" to the whole workspace.

Click Replace

In the Replace window enter your classpathentry tag that points to your new jar.

enter image description here

Click OK.

*If you don't have an old jar that needs replacing you can just replace the end </classpath> Tag with <classpathentry kind="lib" path="C:/myjars/new-jar.jar"/> </classpath> to insert a reference to the new jar.

ferekdoley
  • 139
  • 1
  • 8
1

Yes there is way. Create one common project to hold all common libraries used by all projects(call it as test1). Create a folder lib and copy all libraries here. Right click on the properties of this project add all these libraries to build path. enter image description here


Make all projects depend on this project. How?

Each project has a file called .classpath in its folder. We need to tweak it.

Press Ctrl + H.

Enter "</classpath>" in "Containing text" text box.

Check "Regular expression" button.

In "Filename patterns" text box enter ".classpath"

Click on Search button.

In Scope choose "workspace".

In Search view all files will be displayed. In Search view menu choose "Show as List" option.

Now with the help of Ctrl and Shift keys you can easily select/deselect many item. Select all items you want to make them to dependent on test1.

Right click and choose "Replace Selected". Enter data as shown below

enter image description here

Note: Here I choose Java project. In case of other project type you need to find out string to replace by adding dependency using UI.


That's it you can add and remove common libraries in test1 project. But be careful while exporting project. I haven't tested it but hope it works after export also. Please let me know in case its not working.

enter image description here

Chandrayya G K
  • 8,719
  • 5
  • 40
  • 68