- 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
2.5 KiB
How to Use — inject-via-java-api (JuiceAgent)
This example demonstrates injecting JuiceAgent into a running JVM process
using the Java API (JNI), without needing injector.exe.
Prerequisites
- Java 8+ installed and available in
PATH - JuiceAgent native DLLs (
libinject.dll,libloader.dll,libagent.dll) placed in the same directory as this example - A
config.tomlfile configured for your use case
Quick Start
Step 1: Build
Run build.bat to compile both the injector and the target jars:
> build.bat
Step 2: Run the Target JVM
Open a terminal and start the target JVM:
> run.bat
The target JVM will start and print its PID periodically. Keep it running.
Step 3: Run the Injector
Open another terminal and run the injector:
> run_injector.bat
You will be prompted to enter:
PID: the target JVM process ID (shown in the target terminal)DLL: path tolibinject.dll(e.g..\libinject.dll)config_path: directory containingconfig.toml(leave empty for current dir)
Step 4: Verify
If the injection is successful, the target JVM will load the JAR specified
in config.toml and execute its entry method.
Files
| File | Description |
|---|---|
build.bat |
Build all jars (injector + target) |
run.bat |
Start the target JVM |
run_injector.bat |
Run the JavaInjector to inject into the target JVM |
config.toml |
JuiceAgent configuration file |
injector/ |
JavaInjector source code and build script |
target/ |
Target JVM source code and build script |
Configuration (config.toml)
[JuiceAgent]
Version = 2
JuiceAgentNativeLibraryPath = ""
[JarLoader]
Enabled = true
Mode = "BuiltIn"
InjectionDir = "./injection"
JarPath = "./demo.jar"
EntryClass = "Example.Main"
EntryMethod = "run"
JarPath: the JAR to load into the target JVMEntryClass: the fully qualified class name with the entry methodEntryMethod: must be apublic static voidmethod with no parametersInjectionDir: directory containing dependency JARs loaded before the main JAR
Troubleshooting
-
Error: JuiceAgent-JavaInjector-1.0-SNAPSHOT.jar not found: Runbuild.batfirst to compile the injector. -
java.lang.UnsatisfiedLinkError: Ensurelibinject.dllis in the current directory or provide the full path. -
Injection has no effect: Verify that
config.tomlis in the directory you specified asconfig_path, and that the paths insideconfig.tomlare correct relative to that directory.