请输入您要查询的百科知识:

 

词条 JRuntime
释义

  1. Usage

      Dynamic class compilation    Dynamic block execution    Dynamic class modification  

  2. External links

{{Orphan|date=February 2009}}{{Infobox Software |
  name                   = JRuntime |  developer              = Helion-Prime Solutions Ltd. |  latest_release_version = 1.0 |  latest_release_date    = {{release date|2008|06|24}} |  operating_system       = Cross-platform |  programming_language   = Java |   genre                  = Library |  license                = GNU Lesser General Public License |  website                = JRuntime Home Page

}}

JRuntime is the simple library for Java. It makes easier an access to Java 6 compiler API.

This library enables compiling, executing and modifying Java-code dynamically while the program is working.

Usage

Dynamic class compilation

String classDef = 	"public class MyClass {"+	"	public String toString() {" +	"		return \\"MyClass\\";" +	"	}"+	"}";RuntimeClass runtimeClass = new RuntimeClass(classDef);System.out.println(runtimeClass.newInstance());

Dynamic block execution

RuntimeBlock sum = new RuntimeBlock(	"return (Integer)params[0]+(Integer)params[1];");System.out.println(sum.invoke(1, 2));System.out.println(sum.invoke(5, 100));

Dynamic class modification

public class ClassToModify {	public String simpleMethod(String text) {		System.out.println("Text: " + text);		return text;	}}...MutableRuntimeClass<ClassToModify> clazz =		new MutableRuntimeClass<ClassToModify>(ClassToModify.class);ClassToModify instance = clazz.newInstance(new SimpleMutator() {	@Override	public void onBeforeMethod(Object instance, Method method,			Object... params) {		System.out.println("Before method: " + method.getName() + 				", params: " + Arrays.toString(params));	}	@Override	public Object onAfterMethod(Object instance, Method method,			Object result, Object... params) {		System.out.println("After method: " + method.getName() + 				", params: " + Arrays.toString(params));		return result;	}});instance.simpleMethod("Test mutable class!!!");

External links

  • JRuntime Home Page
  • Java Compiler API

1 : Java (programming language) libraries

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/15 20:20:02