Skip to content

Commit 1798f08

Browse files
committed
fix: fix Java
1 parent b96d7f5 commit 1798f08

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

examples/HelloWorld.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
class HelloWorld {
22
public static void main(String[] args) {
33
System.out.println("Hello, World!");
4+
// test UTF-8
5+
System.out.println("سلام");
46
}
57
}

lib/grammars/java.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ export const Java = {
2525
const className = GrammarUtils.Java.getClassName(context)
2626
const classPackages = GrammarUtils.Java.getClassPackage(context)
2727
const sourcePath = GrammarUtils.Java.getProjectPath(context)
28+
const tempFolder = GrammarUtils.createTempFolder("jar-")
29+
const cmd = `javac -encoding UTF-8 -sourcepath '${sourcePath}' -d '${tempFolder}' '${context.filepath}' && java -D'file.encoding'='UTF-8' -cp '${tempFolder}' ${classPackages}${className}`
2830
if (windows) {
29-
return [`/c javac -Xlint ${context.filename} && java ${className}`]
31+
return [`/c ${cmd}`]
3032
} else {
31-
return [
32-
"-c",
33-
`javac -J-Dfile.encoding=UTF-8 -sourcepath '${sourcePath}' -d /tmp '${context.filepath}' && java -Dfile.encoding=UTF-8 -cp /tmp:%CLASSPATH ${classPackages}${className}`,
34-
]
33+
return ["-c", cmd]
3534
}
3635
},
3736
},

0 commit comments

Comments
 (0)