{"id":19765688,"url":"https://github.com/openhft/java-runtime-compiler","last_synced_at":"2025-05-13T21:05:45.252Z","repository":{"id":10782162,"uuid":"13050340","full_name":"OpenHFT/Java-Runtime-Compiler","owner":"OpenHFT","description":"Java Runtime Compiler","archived":false,"fork":false,"pushed_at":"2025-03-12T23:12:25.000Z","size":284,"stargazers_count":676,"open_issues_count":8,"forks_count":147,"subscribers_count":49,"default_branch":"ea","last_synced_at":"2025-04-11T10:00:16.352Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenHFT.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.adoc","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2013-09-24T00:05:33.000Z","updated_at":"2025-03-31T07:51:59.000Z","dependencies_parsed_at":"2023-01-13T16:09:08.206Z","dependency_job_id":"0b6de2c4-4a54-443e-bc22-33aa493b2d65","html_url":"https://github.com/OpenHFT/Java-Runtime-Compiler","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenHFT%2FJava-Runtime-Compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenHFT%2FJava-Runtime-Compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenHFT%2FJava-Runtime-Compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenHFT%2FJava-Runtime-Compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenHFT","download_url":"https://codeload.github.com/OpenHFT/Java-Runtime-Compiler/tar.gz/refs/heads/ea","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251311332,"owners_count":21569009,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T04:19:08.122Z","updated_at":"2025-04-28T12:11:08.502Z","avatar_url":"https://github.com/OpenHFT.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"= Chronicle Runtime Compiler\nChronicle Software\n:css-signature: demo\n:toc: macro\n:toclevels: 2\n:icons: font\n\nimage:https://maven-badges.herokuapp.com/maven-central/net.openhft/compiler/badge.svg[caption=\"\",link=https://maven-badges.herokuapp.com/maven-central/net.openhft/compiler]\nimage:https://javadoc.io/badge2/net.openhft/compiler/javadoc.svg[link=\"https://www.javadoc.io/doc/net.openhft/compiler/latest/index.html\"]\n//image:https://javadoc-badge.appspot.com/net.openhft/compiler.svg?label=javadoc[JavaDoc, link=https://www.javadoc.io/doc/net.openhft/compiler]\nimage:https://img.shields.io/github/license/OpenHFT/Java-Runtime-Compiler[GitHub]\nimage:https://img.shields.io/badge/release%20notes-subscribe-brightgreen[link=\"https://chronicle.software/release-notes/\"]\nimage:https://sonarcloud.io/api/project_badges/measure?project=OpenHFT_Java-Runtime-Compiler\u0026metric=alert_status[link=\"https://sonarcloud.io/dashboard?id=OpenHFT_Java-Runtime-Compiler\"]\n\nThis takes a String, compiles it and loads it returning you a class from what you built.\nBy default it uses the current ClassLoader.\nIt supports nested classes, otherwise builds one class at a time.\n\n== On Maven Central\n\nYou can include in your project with\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.openhft\u003c/groupId\u003e\n    \u003cartifactId\u003ecompiler\u003c/artifactId\u003e\n    \u003cversion\u003e\u003c!-- The latest version (see above) --\u003e\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n== Simple example\n\nYou need a CachedCompiler and access to your JDK's tools.jar.\n\n```java\n// dynamically you can call\nString className = \"mypackage.MyClass\";\nString javaCode = \"package mypackage;\\n\" +\n                 \"public class MyClass implements Runnable {\\n\" +\n                 \"    public void run() {\\n\" +\n                 \"        System.out.println(\\\"Hello World\\\");\\n\" +\n                 \"    }\\n\" +\n                 \"}\\n\";\nClass\u003c?\u003e aClass = CompilerUtils.CACHED_COMPILER.loadFromJava(className, javaCode);\nRunnable runner = (Runnable) aClass.newInstance();\nrunner.run();\n```\n     \nI suggest making your class implement a KnownInterface of your choice as this will allow you to call/manipulate instances of you generated class.\n\nAnother more hacky way is to use this to override a class, provided it hasn't been loaded already.  \nThis means you can redefine an existing class and provide the methods and fields used match,\nyou have compiler redefine a class and code already compiled to use the class will still work.\n\n== Using the CachedCompiler.\n\nIn this example, you can configure the compiler to write the files to a specific directory when you are in debug mode.\n       \n```java\nprivate static final CachedCompiler JCC = CompilerUtils.DEBUGGING ?\n                                                   new CachedCompiler(new File(parent, \"src/test/java\"), new File(parent, \"target/compiled\")) :\n                                                   CompilerUtils.CACHED_COMPILER;\n```\n     \nBy selecting the src directory to match where your IDE looks for those files, it will allow your debugger to set into the code you have generated at runtime.\n\nNote: you may need to delete these files if you want to regenerate them.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenhft%2Fjava-runtime-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenhft%2Fjava-runtime-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenhft%2Fjava-runtime-compiler/lists"}