如何在运行时编译和部署 java 类? [英] How can I compile and deploy a java class at runtime?

查看:21
本文介绍了如何在运行时编译和部署 java 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个规则引擎,该引擎执行由条件结构确定的简单分配.规则为 XML 格式是项目的先决条件.我已经将我的 XML 模式建模为类似于简单的代码块.我希望解析 XML,然后将其转换为 Java 代码.然后我希望在运行时编译(并运行)这段代码.这样做意味着我的规则引擎不再充当解释器,而是执行原生 Java 字节码.

I am in the process of writing a rule engine that performs simple assignments as determined by conditional constructs. It is a prerequisite of the project that the rules be in XML format. I have modeled my XML schema to resemble simple code blocks. I wish to parse the XML and to then transform it into Java code. I then wish to compile (and run) this code at runtime. Doing so would mean that my rule engine no longer acts as an interpreter but executes native Java Byte Code.

我已经弄清楚了解析阶段和或多或少的 Java 代码生成阶段.我现在想弄清楚最后一个阶段——运行时编译阶段.

I have figured out the parsing stage and more or less the Java code generation phase. I would now like to figure out the last phase - the compile at runtime phase.

遵循此线程:编译为 java 字节码(不使用 Java) 我了解到以下可能的解决方案:

Following this thread: Compile to java bytecode (without using Java) I have become aware of the following possible solutions:

我希望对这些进行比较,以及在运行时阶段解决 Java 编译问题的其他建议.

I would love a comparison of these as well as other suggestions for solving the Java compile at runtime phase.

推荐答案

您可以将其转换为 Clojure 代码,Clojure 编译器会为您将其转换为字节码.

You could transform it into Clojure code, and the Clojure compiler will turn it into bytecode for you.

这篇关于如何在运行时编译和部署 java 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆