正在编制String作为code可能吗? [英] Is Compiling String as code possible?
问题描述
我有一个应用程序,得到一个HTML文件的内容。
I have an app that gets the content of an html file.
可以说,网页的文字是:
Lets say the text of the page is:
String[] arr = new String[] {"!","@","#"};
for (String str : arr) {
write(str);
}
我可以以某种方式编译这段文字,我的应用程序内运行code?
Can I somehow compile this text and run the code within my app?
感谢
推荐答案
使用 JANINO 。这是一个Java运行时的内存编译器。方式比BCEL和喜欢更简单。
Use Janino. It's a java runtime in-memory compiler. Way easier than BCEL and the likes.
从网页:
什么是JANINO?
JANINO是一种超小型,超快速的Java™编译器。它不仅可以编译一组源文件的一组类文件,如javac工具,而且还可以的它编译在内存中的Java™EX pression,块,类体或源文件,加载字节code和直接在同一个JVM执行它。的JANINO是不打算成为一个开发工具,但运行时编译的目的嵌入式编译器...
Janino is a super-small, super-fast Java™ compiler. Not only can it compile a set of source files to a set of class files like the JAVAC tool, but also can it compile a Java™ expression, block, class body or source file in memory, load the bytecode and execute it directly in the same JVM. Janino is not intended to be a development tool, but an embedded compiler for run-time compilation purposes...
这篇关于正在编制String作为code可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!