[106688] Address removal of old tools.jar when JRE switched
diff --git a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java
index 18d7258..5cd813b 100644
--- a/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java
+++ b/plugins/org.eclipse.jst.server.tomcat.core/tomcatcore/org/eclipse/jst/server/tomcat/core/internal/TomcatServerBehaviour.java
@@ -582,8 +582,23 @@
IPath jrePath = new Path(vmInstall.getInstallLocation().getAbsolutePath());
if (jrePath != null) {
IPath toolsPath = jrePath.append("lib").append("tools.jar");
- if (toolsPath.toFile().exists())
- mergeClasspath(oldCp, JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath));
+ if (toolsPath.toFile().exists()) {
+ IRuntimeClasspathEntry toolsJar = JavaRuntime.newArchiveRuntimeClasspathEntry(toolsPath);
+ // Search for index to any existing tools.jar entry
+ int toolsIndex;
+ for (toolsIndex = 0; toolsIndex < oldCp.size(); toolsIndex++ ) {
+ IRuntimeClasspathEntry entry = (IRuntimeClasspathEntry) oldCp.get(toolsIndex);
+ if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE
+ && entry.getPath().lastSegment().equals("tools.jar")) {
+ break;
+ }
+ }
+ // If existing tools.jar found, replace in case it's different. Otherwise add.
+ if (toolsIndex < oldCp.size())
+ oldCp.set(toolsIndex, toolsJar);
+ else
+ mergeClasspath(oldCp, toolsJar);
+ }
}
}