Access Java API in Groovy Script
2014-03-17 18:20
295 查看
$ cat Hello.java
package test;
public class Hello {
public int myadd(int x, int y) {
}
}
$ cat myapp.groovy
import test.Hello
def hello = new Hello()
println hello.myadd(13, 5)
$ javac Hello.java
$ mkdir test;mv Hello.class test
$ tree
.
├── groovy-all-2.2.1.jar
├── Hello.java
├── myapp.groovy
└── test
$ java -cp .:groovy-all-2.2.1.jar groovy.ui.GroovyMain myapp.groovy
135
Note:
You can't use groovy-2.2.1.jar here, or you will get a NoClassDefFoundError;
If your groovy script don't access other Java class, you can simply run "java -jar groovy-all-2.2.1.jar myapp.groovy".
package test;
public class Hello {
public int myadd(int x, int y) {
return 10 * x + y;
}
}
$ cat myapp.groovy
import test.Hello
def hello = new Hello()
println hello.myadd(13, 5)
$ javac Hello.java
$ mkdir test;mv Hello.class test
$ tree
.
├── groovy-all-2.2.1.jar
├── Hello.java
├── myapp.groovy
└── test
└── Hello.class
$ java -cp .:groovy-all-2.2.1.jar groovy.ui.GroovyMain myapp.groovy
135
Note:
You can't use groovy-2.2.1.jar here, or you will get a NoClassDefFoundError;
If your groovy script don't access other Java class, you can simply run "java -jar groovy-all-2.2.1.jar myapp.groovy".
相关文章推荐
- Exception in thread "main" java.sql.SQLException: Access denied for user 'root'@'localhost' (using p
- poi项目apache组织,Java API To Access Microsoft Format Files
- Exception in thread "main" java.sql.SQLException: Access denied for user ''@'localhost' (using passw
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPac
- How to access local directory with script executed in oozie?
- MetaWeblog API in Java
- Java核心API -- 10(File、RandomAccessFile)
- Java API To Access Microsoft Format Files
- POI-HSSF and POI-XSSF - Java API To Access Microsoft Excel Format Files
- [Java核心API]IO流--随机访问文件RandomAccessFile
- Exception from System.loadLibrary(smjavaagentapi) java.lang.UnsatisfiedLinkError: no smjavaagentapi in java.library.path
- java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
- 解决Hive Exception in thread "main" java.lang.IllegalAccessError
- Apache Project:POI-HSSF - Java API To Access Microsoft Excel Format Files(ZT)
- Tricks with Direct Memory Access in Java
- 使用Desktop API in Java SE 6打开文件或者网页
- 处理教材:Access Control of "Thinking in Java"
- java.lang.IllegaAccessError:Class ref in pre-verified class resoved to unexpected implementation
- Compile Java Codes in Linux Shell instead of Ant Script