How to use 'go java' in Go

Every line of 'go java' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
49func Java(m *Module, info copyright.Info, gen chan Generate, path string) {
50 settings := JavaSettings{
51 Module: m,
52 JavaPackage: m.Directives["java.package"],
53 Copyright: strings.TrimSpace(copyright.Build("generated_java", info)),
54 }
55 settings.MemberPrefix, _ = m.Directives["java.member_prefix"]
56 source, _ := m.Directives["java.source"]
57 indent, _ := m.Directives["java.indent"]
58 indent = strings.Trim(indent, `"`)
59 pkgPath := strings.Replace(settings.JavaPackage, ".", "/", -1)
60 factory := JavaFactory{JavaSettings: settings.clone(), Structs: []*Struct{}}
61 for _, s := range m.Structs {
62 if s.Tags.Get("java") == "disable" {
63 continue
64 }
65 if settings.JavaPackage == "com.google.gapid.service.snippets" &&
66 s.Name() == "fieldPath" {
67 s.Exported = true
68 }
69 gen <- Generate{
70 Name: "Java.File",
71 Arg: JavaClass{JavaSettings: settings.clone(), Struct: s},
72 Output: filepath.Join(path, source, pkgPath, settings.ClassName(s.Name())+".java"),
73 Indent: indent,
74 }
75 factory.Structs = append(factory.Structs, s)
76 }
77 if len(factory.Structs) > 0 {
78 gen <- Generate{
79 Name: "Java.Factory",
80 Arg: factory,
81 Output: filepath.Join(path, source, pkgPath, "Factory.java"),
82 Indent: indent,
83 }
84 }
85}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

284func GetJava() string {
285 workDir := systemutil.GetWorkDir()
286 if systemutil.IsMacos() {
287 return workDir + "/jre/Contents/Home/bin/java"
288 } else {
289 return workDir + "/jre/bin/java"
290 }
291}

Related snippets