java 内使用 groovy 脚本,JSR-223(Scripting for the Ja...
2013-11-06 00:00
405 查看
在Java里需要用到 动态脚本的地方,可以使用groovy,比较方便。
他支持多个JVM平台的脚本语言。
这里使用到groovy我们还需要,groovy对应的实现代码。
maven
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.6</version>
</dependency>
groovy-all-x.x.x.jar 提供了groovy 本身的库,以及对JSR-233的实现。
// require(url:'https://scripting.dev.java.net', jar:'groovy-engine.jar') import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; public class CalcMain { public static void main(String[] args) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("groovy"); // basic example System.out.println(engine.eval("(1..10).sum()")); // example showing scripting variables engine.put("first", "HELLO"); engine.put("second", "world"); System.out.println(engine.eval("first.toLowerCase() + second.toUpperCase()")); } }JSR-233 自JAVA6开始就携带了,但是他只是一个规范。
他支持多个JVM平台的脚本语言。
这里使用到groovy我们还需要,groovy对应的实现代码。
maven
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.1.6</version>
</dependency>
groovy-all-x.x.x.jar 提供了groovy 本身的库,以及对JSR-233的实现。
相关文章推荐
- Programming Groovy: Dynamic Productivity for the Java Developer
- JAVA与groovy脚本的结合使用
- JAVA与groovy脚本的结合使用
- [置顶] 【JAVA】Eclipse中使用git进行pull远程代码,报错The current branch is not configured for pull No value for key branc
- Contexts and Dependency Injection for the Java EE Platform(CDI,JSR-299)
- Java中TOMCAT下使用JavaBean出现The value for the useBean class attribute is invalid 问题 .
- The Java™ Tutorials — Generics :Guidelines for Wildcard Use 通配符使用指南
- Scripting for the Java Platform
- 首次使用Oracle SQL Developer 提示: enter the full pathname for java.exe
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"(使用forEach时出错)
- 使用HttpClient携带证书报错_Certificate for <IP> doesn't match any of the subject alternative names:[域名]
- 如何使用git管理你的java脚本(入门篇)
- thrift for java的使用
- C++中使用array报错 requires compiler and library surpport for the ISO c++ 2011 standard
- Unable to execute dex: java.nio.BufferOverflowException. Check the Eclipse log for stack trace.
- Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core
- windows下 安装后的 Oracle SQL Developer 不能用,出现一个对话框提示:Enter the full pathname for java.exe
- nGrinder 的 Groovy 脚本使用指南(HTTP 请求详解)
- 使用版本 1.0.0 的 Azure ARM SDK for Java 创建虚拟机时报错
- Groovy:java.lang.String.positive() is applicable for argument types: () values: []