Java 5 中的动态编译选项

Options for dynamic compilation in Java 5(Java 5 中的动态编译选项)

本文介绍了Java 5 中的动态编译选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 Janino 之外,还有其他选项可用于在 v5 中即时编译和执行 Java 代码吗?我知道 v6 有 Compiler API,但我需要使用 v5 VM.

我基本上需要获取一个包含完整 Java 类的字符串,对其进行编译并将其加载到内存中.

解决方案

你想要的是 Janino.我们已经使用了多年.你给它(接近标准的)代码,它给你类,所以你可以使用它们.它实际上有很多不同的模式,并支持 1.5 语法糖和自动装箱等.

如果您调用 javac,您不仅需要为它所做的任何事情做好准备,您还必须处理将类放在正确的位置或制作额外的类加载器.

Janino 很容易.它应该正是您正在寻找的.

Are there any options other than Janino for on-the-fly compiliation and execution of Java code in v5? I know v6 has the Compiler API, but I need to work with the v5 VM.

I essentially need to take a string containing a complete Java class, compile it and load it into memory.

解决方案

What you want is something like Janino. We've used it for years. You give it (near standard) code and it gives you the classes so you can use them. It actually has quite a few different modes and supports the 1.5 syntactic sugar and auto-boxing and such.

If you call javac, not only will you have to be ready for anything it does, you'll then have to handle putting the class in the right place or making an additional classloader.

Janino is very easy. It should be exactly what you are looking for.

这篇关于Java 5 中的动态编译选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Java 5 中的动态编译选项

基础教程推荐