# liquor **Repository Path**: cgb-study/liquor ## Basic Information - **Project Name**: liquor - **Description**: noear:: Java 动态编译小工具 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 74 - **Created**: 2024-09-16 - **Last Updated**: 2024-09-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [![Maven Central](https://img.shields.io/maven-central/v/org.noear/liquor.svg)](https://mvnrepository.com/search?q=g:org.noear%20AND%20liquor) [![Apache 2.0](https://img.shields.io/:license-Apache2-blue.svg)](https://license.coscl.org.cn/Apache2/) [![JDK-8+](https://img.shields.io/badge/JDK-8+-green.svg)](https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html) [![QQ交流群](https://img.shields.io/badge/QQ交流群-22200020-orange)](https://jq.qq.com/?_wv=1027&k=kjB5JNiC) # Liquor for java Java 动态编译小工具。(此工具可兼容 jar in jar 的情况) 本工具的代码主要源自 arthas。相关的知识点比较冷门,甚是珍贵,但也只能用在合适的场景上(切不可滥用)。为了复用方便,特整理成一个小工具包进行长期维护。 零依赖,发布包仅 24KB。 ### 演示 ```xml org.noear liquor 1.1.1 ``` ```java public class DemoApp { public static void main(String[] args) throws Exception{ String className = "HelloWorld"; String classCode = "public class HelloWorld { " + " public static void helloWorld() { " + " System.out.println(\"Hello, world!\"); " + " } " + "}"; DynamicCompiler compiler = new DynamicCompiler(); //添加源码(可多个)并 构建 compiler.addSource(className, classCode).build(); Class clazz = compiler.getClassLoader().loadClass(className); clazz.getMethod("helloWorld").invoke(null); } } ```