|
1 | 1 | # KCL Artifact Library for Java |
2 | 2 |
|
3 | | -## Example |
4 | | - |
5 | | -```java |
6 | | -import com.kcl.api.API; |
7 | | -import com.kcl.api.Spec.*; |
8 | | -import com.kcl.ast.Program; |
9 | | -import com.kcl.util.JsonUtil; |
10 | | - |
11 | | -public class Main { |
12 | | - public void testProgramSymbols() throws Exception { |
13 | | - API api = new API(); |
14 | | - LoadPackage_Result result = api.loadPackage( |
15 | | - LoadPackage_Args.newBuilder().setResolveAst(true).setParseArgs( |
16 | | - ParseProgram_Args.newBuilder().addPaths("./src/test_data/schema.k").build()) |
17 | | - .build()); |
18 | | - String programString = result.getProgram(); |
19 | | - Program program = JsonUtil.deserializeProgram(programString); |
20 | | - result.getSymbolsMap().values().forEach(s -> System.out.println(s)); |
21 | | - } |
22 | | -} |
23 | | -``` |
24 | | - |
25 | | -## Getting Started |
26 | | - |
27 | | -This project is built upon the native KCL core library, and it is released for multiple platforms you can use a classifier to specify the platform you are building the application on. |
28 | | - |
29 | | -### Maven |
30 | | - |
31 | | -Generally, you can first add the `os-maven-plugin` to automatically detect the classifier based on your platform: |
32 | | - |
33 | | -```xml |
34 | | -<build> |
35 | | -<extensions> |
36 | | - <extension> |
37 | | - <groupId>kr.motd.maven</groupId> |
38 | | - <artifactId>os-maven-plugin</artifactId> |
39 | | - <version>1.7.0</version> |
40 | | - </extension> |
41 | | -</extensions> |
42 | | -</build> |
43 | | -``` |
44 | | - |
45 | | -Then add the dependency to `kcl-lib` as follows: |
46 | | - |
47 | | -```xml |
48 | | -<dependencies> |
49 | | -<dependency> |
50 | | - <groupId>com.kcl</groupId> |
51 | | - <artifactId>kcl-lib</artifactId> |
52 | | - <version>${kcl_lib.version}</version> |
53 | | -</dependency> |
54 | | -<dependency> |
55 | | - <groupId>com.kcl</groupId> |
56 | | - <artifactId>kcl-lib</artifactId> |
57 | | - <version>${kcl_lib.version}</version> |
58 | | - <classifier>${os.detected.classifier}</classifier> |
59 | | -</dependency> |
60 | | -</dependencies> |
61 | | -``` |
62 | | - |
63 | | -### Gradle |
64 | | - |
65 | | -For Gradle, you can first add the `com.google.osdetector` to automatically detect the classifier based on your platform: |
66 | | - |
67 | | - |
68 | | -```groovy |
69 | | -plugins { |
70 | | - id "com.google.osdetector" version "1.7.3" |
71 | | -} |
72 | | -``` |
73 | | - |
74 | | -Then add the dependency to `kcl-lib` as follows: |
75 | | - |
76 | | -```groovy |
77 | | -dependencies { |
78 | | - implementation "com.kcl:kcl-lib:0.7.5" |
79 | | - implementation "com.kcl:kcl-lib:0.7.5:$osdetector.classifier" |
80 | | -} |
81 | | -``` |
82 | | - |
83 | | -### Classified Library |
84 | | - |
85 | | -Note that the dependency without classifier ships all classes and resources except the `kcl-lib` shared library. And those with classifier bundle only the shared library. |
86 | | - |
87 | | -For downstream usage, it's recommended: |
88 | | - |
89 | | -+ Depends on the one without the classifier to write code; |
90 | | -+ Depends on the classified ones with "test" for testing. |
91 | | - |
92 | | -To load the shared library correctly, you can choose one of the following approaches: |
93 | | - |
94 | | -+ Append the classified JARs to the classpath at the runtime; |
95 | | -+ Depend on the classified JARs and build a fat JAR (You may need to depend on all the provided classified JARs for running on multiple platforms); |
96 | | -+ Build your own `kcl-lib` shared library and specify `-Djava.library.path` to the folder containing that shared library using the `make` command. |
97 | | - |
98 | | -## Developing |
99 | | - |
100 | | -+ Install Python3 |
101 | | -+ Install Rust |
102 | | -+ Install Java8+ |
103 | | -+ Install Maven |
| 3 | +See [here](https://github.com/kcl-lang/kcl-java) for more information. |
0 commit comments