【Groovy】Groovy 脚本调用 ( Linux 中调用 Groovy 脚本 | Windows 中调用 Groovy 脚本 )

简介: 【Groovy】Groovy 脚本调用 ( Linux 中调用 Groovy 脚本 | Windows 中调用 Groovy 脚本 )

文章目录

前言

一、Linux 中调用 Groovy 脚本

二、Windows 中调用 Groovy 脚本

前言

在 命令行 , Groovy 脚本 , Groovy 类 , Java 类中 , 可以调用 Groovy 脚本 ;



以 【Groovy】Groovy 扩展方法 ( 实例扩展方法配置 | 扩展方法示例 | 编译实例扩展类 | 打包实例扩展类字节码到 jar 包中 | 测试使用 Thread 实例扩展方法 ) 博客为例 , 将 Thread 类的扩展方法定义在 ThreadExt 类中 , 并将其打包封装到 thread.jar 文件中 ;


在 Groovy 脚本中运行 Thread 的扩展文件 , 需要依赖于 thread.jar 文件 ;






一、Linux 中调用 Groovy 脚本


在 Linux 中运行 Groovy 脚本 , 需要在第一行处配置


#!/usr/bin/env groovy -classpath thread.jar


内容 , 然后可以运行


./ThreadExtApplication.groovy


命令 , 即可在 Linux 命令行 , 运行 Groovy 脚本 ;



注意 , -classpath 参数的设定 , 指定的 thread.jar 依赖 , 位置一定要准确 , 与 ThreadExtApplication.groovy 脚本要在相同的目录 , 才能执行成功 ;



执行时 , 如果想要加参数 , 在命令末尾添加若干参数 , 在 Groovy 脚本中 , 通过 String[] args 获取执行参数 ; 多个参数之间使用空格隔开 ;


./ThreadExtApplication.groovy arg1 arg2 ... argn



脚本内容示例 :


#!/usr/bin/env groovy -classpath thread.jar
new Thread().hello{
    println "Hello"
}
Thread.hello{
    println "Hello"
}






二、Windows 中调用 Groovy 脚本


Windows 中 , 可以直接运行


groovy -classpath thread.jar ThreadExtApplication.groovy


命令 , 执行 Groovy 脚本 ;



执行时 , 如果想要加参数 , 可以在命令最后 , 添加若干个参数 , 在 Groovy 脚本中 , 通过 String[] args 获取执行参数 ;


groovy -classpath thread.jar ThreadExtApplication.groovy arg1 arg2 ... argn
目录
相关文章
|
1月前
|
安全 Linux 生物认证
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
79 0
Nexpose 8.25.0 for Linux & Windows - 漏洞扫描
|
1月前
|
安全 Linux iOS开发
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
315 53
Binary Ninja 5.1.8104 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
1月前
|
安全 Linux 生物认证
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
146 1
Nexpose 8.24.0 for Linux & Windows - 漏洞扫描
|
1月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
109 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
1月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
177 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
1月前
|
Linux API iOS开发
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
181 14
Binary Ninja 4.2.6455 (macOS, Linux, Windows) - 反编译器、反汇编器、调试器和二进制分析平台
|
1月前
|
Linux 虚拟化 iOS开发
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
340 0
VMware Remote Console 13.0.1 for macOS, Linux, Windows - vSphere 虚拟机控制台的桌面客户端
|
2月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
269 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
2月前
|
JSON 安全 Linux
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
134 1
Nexpose 8.22.0 for Linux & Windows - 漏洞扫描
|
2月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
372 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架