Docs: update config docs to v2 schema and add config.md

- docs: add config.md documenting the v2 schema ([JuiceAgent] / [JarLoader]), key defaults and the BuiltIn / CustomJar modes

- docs: rewrite advanced.md around the JarLoader.Mode = CustomJar workflow instead of the removed JUICEAGENT_API_* environment variables

- readme: migrate the Quick Start config example from v1 to v2 and link docs/config.md, list inject-via-java-api under Examples

- examples: update inject-via-java-api HowToUse docs (.md/.txt, EN/ZH) to the v2 config
This commit is contained in:
xiaozhou233 committed 2026-10-15 20:02:32 +08:00
1 parent af22f80b23
commit 5170d50517
8 files changed
+118 -57

No files matched your search

+25 -15
View File
@@ -1,24 +1,34 @@
# Advanced
## Load Custom API / Directly Load Jar
WARN: This feature didn't implement yet.
### Describe
JuiceAgent loads custom JARs through the following workflow:
JuiceAgent runs in **BuiltIn** mode by default: `libloader` registers the embedded
JuiceAgent-API jar, the agent bootstraps it, and the JarLoader module loads your JAR
and invokes its entry method.
1. Inject `libloader` into the target process.
2. Load **JuiceAgent-API** and execute its initialization entry point.
3. Invoke the `JarLoader` from **JuiceAgent-API** to load the specified JAR into the JVM.
If you don't need JuiceAgent-API — for example you want to provide your own bootstrap
and call an arbitrary class/method — set `JarLoader.Mode` to **`CustomJar`**:
The second step is fully customizable. You can replace **JuiceAgent-API** with your own JAR and call any class method you specify.
```toml
[JuiceAgent]
Version = 2
### Configuration
[JarLoader]
Mode = "CustomJar"
JarPath = "./my-agent.jar"
EntryClass = "com.example.MyBootstrap"
EntryMethod = "start"
```
Set the following environment variables before launching `libloader`:
Workflow in `CustomJar` mode:
```bat
set JUICEAGENT_API_ENABLED=true
set JUICEAGENT_API_JAR=<path-to-your-jar>
set JUICEAGENT_API_CLASS=<target-class-name>
set JUICEAGENT_API_METHOD=<target-method-name>
```
1. `libloader` attaches to the target JVM and reads `config.toml`.
2. It adds `JarPath` to the system class loader search path. JuiceAgent-API is **not** loaded.
3. It invokes `EntryClass.EntryMethod`.
`EntryMethod` must be a `public static void` method that takes no arguments.
> `JarLoader.Enabled` and `JarLoader.InjectionDir` only apply to `BuiltIn` mode; they are
> ignored in `CustomJar` mode.
See [Configuration](config.md) for the complete list of keys.
+65
View File
@@ -0,0 +1,65 @@
# Configuration (`config.toml`)
JuiceAgent reads a single `config.toml` from the **runtime directory** (the directory
passed to the injector / loader; the current working directory is used when none is
given). Paths that start with `./` are resolved against the runtime directory;
absolute paths are used as-is.
The current schema version is **2**. `JuiceAgent.Version` must match the version
expected by the binaries, otherwise the loader stops with a version mismatch error.
## Example
```toml
[JuiceAgent]
Version = 2
JuiceAgentNativeLibraryPath = ""
[JarLoader]
Enabled = true
Mode = "BuiltIn"
InjectionDir = "./injection"
JarPath = "./MyCustomJar.jar"
EntryClass = "Example.Main"
EntryMethod = "run"
```
## `[JuiceAgent]`
| Key | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `Version` | integer | yes | — | Configuration schema version. Must be `2`. |
| `JuiceAgentNativeLibraryPath` | string (path) | no | `./libagent.dll` | Path to `libagent.dll`, loaded by the bootstrap after injection. |
## `[JarLoader]`
| Key | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `Mode` | string | yes | — | How the target JAR is registered: `BuiltIn` or `CustomJar`. |
| `Enabled` | boolean | no | `false` | Run the JarLoader module after the agent is initialized (`BuiltIn` mode only). When `false`, no JAR is loaded and no entry method is invoked. |
| `InjectionDir` | string (path) | no | `./injection` | Directory of dependency JARs loaded before the main JAR (`BuiltIn` mode). |
| `JarPath` | string (path) | see below | `./Entry.jar` (`BuiltIn`) | The JAR to load. |
| `EntryClass` | string | see below | `Example.Main` (`BuiltIn`) | Entry class to invoke after loading the JAR. |
| `EntryMethod` | string | see below | `start` (`BuiltIn`) | Entry method, must be a `public static void` method with no parameters. |
> In `CustomJar` mode, `JarPath`, `EntryClass` and `EntryMethod` are required (there are
> no defaults); `Enabled` and `InjectionDir` are not used.
## Modes
### `BuiltIn` (recommended)
1. `libloader` extracts the embedded **JuiceAgent-API** jar and adds it to the system class loader.
2. The agent bootstraps JuiceAgent-API (`JuiceAgentBootstrap.start`).
3. If `Enabled = true`, the JarLoader module loads every `*.jar` from `InjectionDir`, then loads `JarPath`, and invokes `EntryClass.EntryMethod`.
This is the mode used by most users: keep JuiceAgent-API and just supply the JAR and
entry point to run.
### `CustomJar`
1. `libloader` adds `JarPath` itself to the system class loader. **JuiceAgent-API is not used.**
2. It invokes `EntryClass.EntryMethod` directly.
Use this when you want to bring your own bootstrap and call an arbitrary class/method.
See [Advanced](advanced.md#load-custom-api--directly-load-jar) for details.