首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

Jav8: Java里边调用js代码

2013-07-04 
Jav8: Java里面调用js代码官方:https://code.google.com/p/jav8/An implementation of the Java Scripting

Jav8: Java里面调用js代码
官方:https://code.google.com/p/jav8/

An implementation of the Java Scripting API (JSR223) base on the Google V8 Javascript engine.

Java Specification Request (JSR) 223 helps developers integrate Java technology and scripting languages by defining a standard framework and application programming interface (API) to do the following:

Access and control Java technology-based objects from a scripting environment
Create web content with scripting languages
Embed scripting environments within Java technology-based applications
For more detail, please read the article Scripting for the Java Platform

To use the Jav8 Scripting Engine, place the file jav8-jsr223-xxx.jar to your classpath. Then you could get an instance of the engine this way:

ScriptEngineManager factory = new ScriptEngineManager();ScriptEngine engine = factory.getEngineByName("jav8");And you execute the script with the ScriptEngine.eval method  try {    engine.eval("print('Hello, world!')");  } catch (ScriptException ex) {      ex.printStackTrace();  }
   

热点排行