Skip to content

Commit 22f944a

Browse files
committed
Fix Tomcat logging and MariaDB JDBC for CF mirror dependencies
Fixes two integration test failures caused by migrating dependencies from Maven Central to java-buildpack.cloudfoundry.org S3 bucket. Issue 1: Tomcat CloudFoundryConsoleHandler ClassNotFoundException - Root cause: Java Util Logging (JUL) initializes during early JVM startup when -Djava.util.logging.config.file is set, before the application classloader has access to regular CLASSPATH entries - Previous approach: Added tomcat-logging-support JAR to CLASSPATH in setenv.sh, but JUL's LogManager uses the boot classloader - Fix: Use -Xbootclasspath/a: instead of CLASSPATH to make the JAR available during early JVM initialization - This matches the pattern used by other security providers (Container Security Provider, Luna, ProtectApp) that also need early loading Issue 2: Tomcat logging JAR filename mismatch - Root cause: Code constructed filename from dep.Name + dep.Version + '.RELEASE.jar', assuming Maven Central's naming convention (tomcat-logging-support-3.4.0.RELEASE.jar with DOT before RELEASE) - CF mirror uses normalized naming with hyphen separator (tomcat-logging-support-3.4.0-RELEASE.jar with HYPHEN before RELEASE) - Result: setenv.sh referenced non-existent file, causing ClassNotFoundException - Fix: Use filepath.Base(entry.URI) to extract actual filename from manifest, matching installer's behavior and making code repository-agnostic Issue 3: MariaDB JDBC JAR not found - Root cause: Glob pattern 'mariadb-java-client-*.jar' didn't match actual filename 'mariadb-jdbc-3.5.7.jar' from manifest URI - Fix: Change pattern to 'mariadb-jdbc-*.jar' to match actual basename Files changed: - src/java/containers/tomcat.go: Use boot classpath and derive JAR name from URI - src/java/frameworks/maria_db_jdbc.go: Fix JAR filename glob pattern These fixes make the code resilient to naming convention differences across artifact repositories and ensure proper JVM classloader initialization order.
1 parent 73d8670 commit 22f944a

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/java/containers/tomcat.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,12 @@ func (t *TomcatContainer) installTomcatLoggingSupport() (string, error) {
242242
return "", fmt.Errorf("failed to install Tomcat logging support: %w", err)
243243
}
244244

245-
jarName := fmt.Sprintf("%s-%s.RELEASE.jar", dep.Name, dep.Version)
245+
entry, err := t.context.Manifest.GetEntry(dep)
246+
if err != nil {
247+
return "", fmt.Errorf("failed to get manifest entry for tomcat-logging-support: %w", err)
248+
}
249+
250+
jarName := filepath.Base(entry.URI)
246251
t.context.Log.Info("Successfully installed Tomcat Logging Support %s to tomcat/bin (contains CloudFoundryConsoleHandler)", dep.Version)
247252
return jarName, nil
248253
}
@@ -253,24 +258,17 @@ func (t *TomcatContainer) createSetenvScript(tomcatDir, loggingSupportJar string
253258
binDir := filepath.Join(tomcatDir, "bin")
254259
setenvPath := filepath.Join(binDir, "setenv.sh")
255260

256-
// Build the runtime path to the logging JAR
257-
// At runtime, CATALINA_HOME points to $DEPS_DIR/<idx>/tomcat
258261
jarPath := "$CATALINA_HOME/bin/" + loggingSupportJar
259262

260-
// Create setenv.sh content that adds logging JAR to CLASSPATH
261263
setenvContent := fmt.Sprintf(`#!/bin/sh
262-
# This file is sourced by catalina.sh before starting Tomcat
263-
# Add Tomcat logging support JAR to CLASSPATH for CloudFoundryConsoleHandler
264-
265-
CLASSPATH=$CLASSPATH:%s
264+
JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/a:%s"
266265
`, jarPath)
267266

268-
// Write the setenv.sh file
269267
if err := os.WriteFile(setenvPath, []byte(setenvContent), 0755); err != nil {
270268
return fmt.Errorf("failed to write setenv.sh: %w", err)
271269
}
272270

273-
t.context.Log.Info("Created setenv.sh to add logging support JAR to CLASSPATH")
271+
t.context.Log.Info("Created setenv.sh with logging JAR on boot classpath")
274272
return nil
275273
}
276274

src/java/frameworks/maria_db_jdbc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
package frameworks
1717

1818
import (
19-
"github.com/cloudfoundry/java-buildpack/src/java/common"
2019
"fmt"
20+
"github.com/cloudfoundry/java-buildpack/src/java/common"
2121
"path/filepath"
2222
"strings"
2323
)
@@ -68,7 +68,7 @@ func (f *MariaDBJDBCFramework) Supply() error {
6868
}
6969

7070
// Find the installed JAR
71-
jarPattern := filepath.Join(mariadbDir, "mariadb-java-client-*.jar")
71+
jarPattern := filepath.Join(mariadbDir, "mariadb-jdbc-*.jar")
7272
matches, err := filepath.Glob(jarPattern)
7373
if err != nil {
7474
return fmt.Errorf("failed to search for MariaDB JDBC JAR: %w", err)

0 commit comments

Comments
 (0)