Skip to content

Commit

Permalink
support both environment method and arg method
Browse files Browse the repository at this point in the history
  • Loading branch information
Pai2Chen committed Jan 28, 2022
1 parent d7b708a commit 57cec30
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ func main() {
args := os.Args
proPath, _ := filepath.Abs(args[0])
basePath := filepath.Dir(proPath)
isEnv := os.Getenv("CLASSPATH") != ""
classPathIndex := 0

nClassPath := make([]string, 0)
filepath.Walk(basePath+"/lwjgl/", func(path string, info fs.FileInfo, err error) error {
Expand All @@ -21,16 +23,31 @@ func main() {
return err
})

classPath := strings.Split(os.Getenv("CLASSPATH"), ":")
classPathStr := ""

for _, v := range classPath {
if isEnv {
classPathStr = os.Getenv("CLASSPATH")
} else {
for i, arg := range args {
if arg == "-cp" {
classPathIndex = i + 1
classPathStr = args[i+1]
break
}
}
}

for _, v := range strings.Split(classPathStr, ":") {
if !strings.Contains(v, "lwjgl") {
nClassPath = append(nClassPath, v)
}
}

args[classPathIndex] = strings.Join(nClassPath, ":")
cmd := exec.Command(args[1], args[2:]...)
cmd.Env = append(os.Environ(), "CLASSPATH="+strings.Join(nClassPath, ":"))
if isEnv {
cmd.Env = append(os.Environ(), "CLASSPATH=")
}
cmd.Stdout = os.Stdout

//println(strings.Join(nClassPath, ":"))
Expand Down

0 comments on commit 57cec30

Please sign in to comment.