java:dynamic-class-loader
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
java:dynamic-class-loader [2025/01/18 00:06] – created odefta | java:dynamic-class-loader [2025/01/18 00:08] (current) – odefta | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ```java | ||
====== Dynamic Classpath Loading with Java Instrumentation ====== | ====== Dynamic Classpath Loading with Java Instrumentation ====== | ||
Line 8: | Line 7: | ||
==== Basic Agent Class ==== | ==== Basic Agent Class ==== | ||
- | ```java | + | < |
package com.example; | package com.example; | ||
Line 35: | Line 34: | ||
} | } | ||
} | } | ||
- | ``` | + | </ |
==== MANIFEST.MF ==== | ==== MANIFEST.MF ==== | ||
- | ``` | + | < |
Manifest-Version: | Manifest-Version: | ||
Premain-Class: | Premain-Class: | ||
Can-Redefine-Classes: | Can-Redefine-Classes: | ||
Can-Retransform-Classes: | Can-Retransform-Classes: | ||
- | ``` | + | </ |
===== Building ===== | ===== Building ===== | ||
==== Without Maven ==== | ==== Without Maven ==== | ||
- | 1. Compile the class: | + | < |
- | ```bash | + | |
javac DynamicLoader.java | javac DynamicLoader.java | ||
- | ``` | ||
- | 2. Create the JAR with manifest: | ||
- | ```bash | ||
mkdir META-INF | mkdir META-INF | ||
# Create MANIFEST.MF with content above | # Create MANIFEST.MF with content above | ||
jar cfm dynamic-loader.jar META-INF/ | jar cfm dynamic-loader.jar META-INF/ | ||
- | ``` | + | </ |
==== With Maven ==== | ==== With Maven ==== | ||
- | ```xml | + | < |
< | < | ||
< | < | ||
Line 95: | Line 90: | ||
</ | </ | ||
</ | </ | ||
- | ``` | + | </ |
===== Running ===== | ===== Running ===== | ||
==== Basic Usage ==== | ==== Basic Usage ==== | ||
- | ```bash | + | < |
java -javaagent: | java -javaagent: | ||
- | ``` | + | </ |
==== Example Main Class ==== | ==== Example Main Class ==== | ||
- | ```java | + | < |
public class MainApp { | public class MainApp { | ||
public static void main(String[] args) { | public static void main(String[] args) { | ||
Line 113: | Line 108: | ||
} | } | ||
} | } | ||
- | ``` | + | </ |
===== Important Notes ===== | ===== Important Notes ===== | ||
Line 134: | Line 129: | ||
===== Example Directory Structure ===== | ===== Example Directory Structure ===== | ||
- | ``` | + | < |
project/ | project/ | ||
+ | │ | ||
├── src/ | ├── src/ | ||
│ | │ | ||
Line 142: | Line 138: | ||
│ | │ | ||
│ | │ | ||
+ | │ | ||
├── libs/ | ├── libs/ | ||
│ | │ | ||
│ | │ | ||
+ | │ | ||
├── pom.xml | ├── pom.xml | ||
└── README.md | └── README.md | ||
- | ``` | + | </ |
===== References ===== | ===== References ===== | ||
* [[https:// | * [[https:// | ||
* [[https:// | * [[https:// | ||
- | ``` |
java/dynamic-class-loader.1737151564.txt.gz · Last modified: 2025/01/18 00:06 by odefta