←Older revision |
Revision as of 14:19, 19 April 2023 |
Line 10: |
Line 10: |
| import java.net.URI; | | import java.net.URI; |
| import java.net.URISyntaxException; | | import java.net.URISyntaxException; |
| + | import java.util.ArrayList; |
| import java.util.Arrays; | | import java.util.Arrays; |
| import java.util.Collections; | | import java.util.Collections; |
Line 27: |
Line 28: |
| public static void main(String... args) throws Exception { | | public static void main(String... args) throws Exception { |
| JavaCompiler compiler = javax.tools.ToolProvider.getSystemJavaCompiler(); | | JavaCompiler compiler = javax.tools.ToolProvider.getSystemJavaCompiler(); |
- | List<String> arguments = Arrays.asList(args); | + | List<String> arguments = new ArrayList<>(Arrays.asList(args)); |
| + | arguments.add("-d"); |
| + | arguments.add("."); |
| List<JavaFileObject> sources = Collections.singletonList(new Src(CODE)); | | List<JavaFileObject> sources = Collections.singletonList(new Src(CODE)); |
| JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, arguments, null, sources); | | JavaCompiler.CompilationTask task = compiler.getTask(null, null, null, arguments, null, sources); |
Line 97: |
Line 100: |
| | | |
| <source lang="bash"> | | <source lang="bash"> |
- | $ mkdir -p META-INF/services
| + | $ curl -o compiler.jar https://repo1.maven.org/maven2/org/frgaal/compiler/20.0.0/compiler-20.0.0.jar |
- | $ echo com.sun.tools.javac.api.JavacTool > META-INF/services/javax.tools.JavaCompiler
| + | |
- | $ curl -o compiler.jar https://repo1.maven.org/maven2/org/frgaal/compiler/18.0.0/compiler-18.0.0.jar | + | |
| $ /jdk-11/bin/java --limit-modules java.base,jdk.zipfs -cp compiler.jar:. ModernJavaCompiler | | $ /jdk-11/bin/java --limit-modules java.base,jdk.zipfs -cp compiler.jar:. ModernJavaCompiler |
| warning: [options] system modules path not set in conjunction with -source 17 | | warning: [options] system modules path not set in conjunction with -source 17 |
Line 111: |
Line 112: |
| Hey, using '''record''' on JDK-11! | | Hey, using '''record''' on JDK-11! |
| | | |
- | Having '''record''' (and other [[JDK]]-18 language features) available on old JDKs is great, isn't it? All that is necessary is to provide extra {{JDK|java/util|ServiceLoader}} registration in ''META-INF/services'' path on the class path. Then the [[Frgaal]] compiler gets picked up and is used for compilation even on older [[JDK]]s. | + | Having '''record''' (and other [[JDK]]-20 language features) available on old JDKs is great, isn't it? |
| | | |
| | | |
| Embed [[Frgaal]] into your own programs and use the latest [[Java]] features on any [[JDK]]! | | Embed [[Frgaal]] into your own programs and use the latest [[Java]] features on any [[JDK]]! |