Skip to content

Commit 4f82e1c

Browse files
adamdecafFiloSottile
authored andcommitted
java: fix paths for Windows and JRE (#54)
Fixes #53
1 parent 70f19a1 commit 4f82e1c

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

truststore_java.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"hash"
1414
"os"
1515
"os/exec"
16-
"path"
1716
"path/filepath"
17+
"runtime"
1818
"strings"
1919
)
2020

@@ -29,17 +29,31 @@ var (
2929
)
3030

3131
func init() {
32+
if runtime.GOOS == "windows" {
33+
keytoolPath = filepath.Join("bin", "keytool.exe")
34+
} else {
35+
keytoolPath = filepath.Join("bin", "keytool")
36+
}
37+
3238
if v := os.Getenv("JAVA_HOME"); v != "" {
3339
hasJava = true
3440
javaHome = v
3541

36-
_, err := os.Stat(path.Join(v, "bin/keytool"))
42+
_, err := os.Stat(filepath.Join(v, keytoolPath))
3743
if err == nil {
3844
hasKeytool = true
39-
keytoolPath = path.Join(v, "bin/keytool")
45+
keytoolPath = filepath.Join(v, keytoolPath)
4046
}
4147

42-
cacertsPath = path.Join(v, "jre/lib/security/cacerts")
48+
_, err = os.Stat(filepath.Join(v, "lib", "security", "cacerts"))
49+
if err == nil {
50+
cacertsPath = filepath.Join(v, "lib", "security", "cacerts")
51+
}
52+
53+
_, err = os.Stat(filepath.Join(v, "jre", "lib", "security", "cacerts"))
54+
if err == nil {
55+
cacertsPath = filepath.Join(v, "jre", "lib", "security", "cacerts")
56+
}
4357
}
4458
}
4559

0 commit comments

Comments
 (0)