MCPcopy Create free account
hub / github.com/cloudfoundry/java-buildpack / findJavaHome

Method findJavaHome

src/java/jres/zing.go:134–161  ·  view source on GitHub ↗

findJavaHome locates the actual JAVA_HOME directory after extraction Zing JRE tarballs usually extract to zing* subdirectories

()

Source from the content-addressed store, hash-verified

132// findJavaHome locates the actual JAVA_HOME directory after extraction
133// Zing JRE tarballs usually extract to zing* subdirectories
134func (z *ZingJRE) findJavaHome() (string, error) {
135 entries, err := os.ReadDir(z.jreDir)
136 if err != nil {
137 return "", fmt.Errorf("failed to read JRE directory: %w", err)
138 }
139
140 // Look for zing* subdirectory
141 for _, entry := range entries {
142 if entry.IsDir() {
143 name := entry.Name()
144 // Check for common Zing JRE directory patterns
145 if len(name) >= 4 && name[:4] == "zing" {
146 path := filepath.Join(z.jreDir, name)
147 // Verify it has a bin directory with java
148 if _, err := os.Stat(filepath.Join(path, "bin", "java")); err == nil {
149 return path, nil
150 }
151 }
152 }
153 }
154
155 // If no subdirectory found, check if jreDir itself is valid
156 if _, err := os.Stat(filepath.Join(z.jreDir, "bin", "java")); err == nil {
157 return z.jreDir, nil
158 }
159
160 return "", fmt.Errorf("could not find valid JAVA_HOME in %s", z.jreDir)
161}
162
163// writeProfileDScript creates the java.sh profile.d script
164// This script sets JAVA_HOME, JRE_HOME, and updates PATH at application runtime

Callers 2

SupplyMethod · 0.95
FinalizeMethod · 0.95

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected