Skip to content

Commit 25ffdb0

Browse files
RoiSoleilHélios GILLES
andauthored
Property to tell to Tomcat to map JARs in WEB-INF/lib or WEB-INF/classes (#422)
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: <Resources> <PostResources base="D:\Projects\external\classes" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes"/> <PostResources base="D:\Projects\lib\library1.jar" className="org.apache.catalina.webresources.JarResourceSet" webAppMount="/WEB-INF/classes"/> </Resources> 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.` Co-authored-by: Hélios GILLES <h-gilles@efluid.fr>
1 parent 66400f0 commit 25ffdb0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/Tomcat8xStandaloneLocalConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,16 @@ private void writeDirectoryPostResource(Element postResourceEl, String path)
203203
*/
204204
private void writeJarPostResource(StringBuilder sb, String path)
205205
{
206+
if (Boolean.parseBoolean(getPropertyValue(TomcatPropertySet.CONTEXT_MAPJARSTOWEBINFCLASSES))) {
207+
sb.append("className=\"" + JAR_RESOURCE_SET + "\" base=\"");
208+
sb.append(path.replace("&", "&amp;"));
209+
sb.append("\" webAppMount=\"/WEB-INF/classes/");
210+
} else {
206211
sb.append("className=\"" + FILE_RESOURCE_SET + "\" base=\"");
207212
sb.append(path.replace("&", "&amp;"));
208213
sb.append("\" webAppMount=\"/WEB-INF/lib/");
209214
sb.append(getFileHandler().getName(path).replace("&", "&amp;"));
215+
}
210216
}
211217

212218
/**
@@ -217,10 +223,16 @@ private void writeJarPostResource(StringBuilder sb, String path)
217223
*/
218224
private void writeJarPostResource(Element postResourceEl, String path)
219225
{
226+
if (Boolean.parseBoolean(getPropertyValue(TomcatPropertySet.CONTEXT_MAPJARSTOWEBINFCLASSES))) {
227+
postResourceEl.setAttribute("className", JAR_RESOURCE_SET);
228+
postResourceEl.setAttribute("base", path.replace("&", "&amp;"));
229+
postResourceEl.setAttribute("webAppMount", "/WEB-INF/classes/");
230+
} else {
220231
postResourceEl.setAttribute("className", FILE_RESOURCE_SET);
221232
postResourceEl.setAttribute("base", path.replace("&", "&amp;"));
222233
postResourceEl.setAttribute("webAppMount", "/WEB-INF/lib/"
223234
+ getFileHandler().getName(path).replace("&", "&amp;"));
235+
}
224236
}
225237

226238
/**

core/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/TomcatPropertySet.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public interface TomcatPropertySet
5454
*/
5555
String CONTEXT_ALLOWWEBJARS = "cargo.tomcat.context.addWebinfClassesResources";
5656

57+
/**
58+
* Whether the contexts for deployed webapplications should map JARs to WEB-INF/classes
59+
*/
60+
String CONTEXT_MAPJARSTOWEBINFCLASSES = "cargo.tomcat.context.mapJarToWebinfClasses";
61+
5762
/**
5863
* Whether WAR deployables should be copied or referenced.
5964
*/

0 commit comments

Comments
 (0)