From 42a6ca26adc097c9ca44195f10b0a70cd3d92168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9lios=20GILLES?= Date: Mon, 27 Nov 2023 16:31:23 +0100 Subject: [PATCH] Property to tell to Tomcat to map JARs in WEB-INF/lib or WEB-INF/classes Use case : Chapter Ordering in https://tomcat.apache.org/tomcat-8.0-doc/config/resources.html `Since both resources are PostResources, it might be expected that D:\Projects\external\classes will be searched for classes before D:\Projects\lib\library1.jar. However, by adding the JAR using a FileResourceSet, the JAR is mapped to /WEB-INF/lib and will be processed at application start along with the other JARs in /WEB-INF/lib. The classes from the JAR file will be added to the ClassResources which means they will be searched before the classes from D:\Projects\external\classes. If the desired behaviour is that D:\Projects\external\classes is searched before D:\Projects\lib\library1.jar then a slightly different configuration is required: In short, the JAR file should be added as a JarResourceSet mapped to /WEB-INF/classes rather than using a FileResourceSet mapped to /WEB-INF/lib.` --- .../tomcat/Tomcat8xStandaloneLocalConfiguration.java | 12 ++++++++++++ .../cargo/container/tomcat/TomcatPropertySet.java | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/Tomcat8xStandaloneLocalConfiguration.java b/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/Tomcat8xStandaloneLocalConfiguration.java index e4879dd70f..7afd8fe39d 100644 --- a/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/Tomcat8xStandaloneLocalConfiguration.java +++ b/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/Tomcat8xStandaloneLocalConfiguration.java @@ -203,10 +203,16 @@ private void writeDirectoryPostResource(Element postResourceEl, String path) */ private void writeJarPostResource(StringBuilder sb, String path) { + if (Boolean.parseBoolean(getPropertyValue(TomcatPropertySet.CONTEXT_MAPJARSTOWEBINFCLASSES))) { + sb.append("className=\"" + JAR_RESOURCE_SET + "\" base=\""); + sb.append(path.replace("&", "&")); + sb.append("\" webAppMount=\"/WEB-INF/classes/"); + } else { sb.append("className=\"" + FILE_RESOURCE_SET + "\" base=\""); sb.append(path.replace("&", "&")); sb.append("\" webAppMount=\"/WEB-INF/lib/"); sb.append(getFileHandler().getName(path).replace("&", "&")); + } } /** @@ -217,10 +223,16 @@ private void writeJarPostResource(StringBuilder sb, String path) */ private void writeJarPostResource(Element postResourceEl, String path) { + if (Boolean.parseBoolean(getPropertyValue(TomcatPropertySet.CONTEXT_MAPJARSTOWEBINFCLASSES))) { + postResourceEl.setAttribute("className", JAR_RESOURCE_SET); + postResourceEl.setAttribute("base", path.replace("&", "&")); + postResourceEl.setAttribute("webAppMount", "/WEB-INF/classes/"); + } else { postResourceEl.setAttribute("className", FILE_RESOURCE_SET); postResourceEl.setAttribute("base", path.replace("&", "&")); postResourceEl.setAttribute("webAppMount", "/WEB-INF/lib/" + getFileHandler().getName(path).replace("&", "&")); + } } /** diff --git a/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/TomcatPropertySet.java b/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/TomcatPropertySet.java index 4b8f555e49..b2ce6723ef 100644 --- a/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/TomcatPropertySet.java +++ b/core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/TomcatPropertySet.java @@ -54,6 +54,11 @@ public interface TomcatPropertySet */ String CONTEXT_ALLOWWEBJARS = "cargo.tomcat.context.addWebinfClassesResources"; + /** + * Whether the contexts for deployed webapplications should map JARs to WEB-INF/classes + */ + String CONTEXT_MAPJARSTOWEBINFCLASSES = "cargo.tomcat.context.mapJarToWebinfClasses"; + /** * Whether WAR deployables should be copied or referenced. */