jeb1支持java脚本和python脚本.jeb2目前只支持python脚本.
就行写了插件支持下java脚本.不过还是有局限性,无法对ui进行操控
原理
通过插件对java脚本文件进行编译,动态加载执行run方法并传入参数IEnginesContext,通过这个参数可以拿到,不少东西,可以参考api
File files=new File(PluginsContext.ScriptsPath);
URL url=files.toURI().toURL();
ClassLoader loader=new URLClassLoader(new URL[]{url},iEnginesContext.getClass().getClassLoader());
Class Scriptclass=loader.loadClass(list.get(index - 1).replace(".java", ""));
Object object=Scriptclass.newInstance();
Class[] args1 = new Class[1];
args1[0]=IEnginesContext.class;
Method method = Scriptclass.getDeclaredMethod("run",args1);
method.invoke(object,iEnginesContext);
脚本编写
public class test {
private ILogger logger= GlobalLog.getLogger(this.getClass());
public void run(IEnginesContext iEnginesContext){
//这里编写脚本
for (int i = 0; i < 10 ; i++) {
try {
logger.info("i is :%d",i);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
使用
将test.java文件复制scripts文件夹下,执行插件
执行结果:
下载地址:
链接:http://pan.baidu.com/s/1qYOXzhq 密码:m80l