Skip to content

Commit d73f270

Browse files
committed
fix: fix execution of Java files + support UTF-8 encoding
1 parent 5a61f1f commit d73f270

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

examples/HelloWorld.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class HelloWorld {
22
public static void main(String[] args) {
33
System.out.println("Hello, World!");
4+
System.out.println("سلام");
45
}
56
}

lib/grammars/java.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ export const Java = {
1919
const className = GrammarUtils.Java.getClassName(context)
2020
const classPackages = GrammarUtils.Java.getClassPackage(context)
2121
const sourcePath = GrammarUtils.Java.getProjectPath(context)
22-
if (windows) {
23-
return [`/c javac ーJ-Dfile.encoding=UTF-8 -Xlint ${context.filename} && java -Dfile.encoding=UTF-8 ${className}`]
24-
} else {
25-
return [
26-
"-c",
27-
`javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`,
28-
]
29-
}
22+
const tempFolder = GrammarUtils.createTempFolder("jar-")
23+
const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${context.filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}`
24+
return GrammarUtils.formatArgs(cmd)
3025
},
3126
},
3227
}

0 commit comments

Comments
 (0)