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

查看:292
本文介绍了如何在运行时编译和部署一个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:

  • ASM
  • BCEL
  • Trove

我会喜欢比较这些以及其他在运行时阶段解决Java编译的建议。

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

推荐答案

使用 Java 6编译器API

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

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