当前位置:网站首页>[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
2022-07-05 22:18:00 【Programmer community】
One 、 Error message
stay Java Class , call Groovy Script , The following error occurred ;
java.io.FileNotFoundException: Y:\002_WorkSpace\003_IDEA\Groovy_Demo\Script.groovy (Y:\002_WorkSpace\003_IDEA\Groovy_Demo\Script.groovy) at groovy.lang.GroovyCodeSource.<init>(GroovyCodeSource.java:108) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:470) at JavaClass.startScript(JavaClass.java:17) at JavaClass.main(JavaClass.java:22)
Two 、 Solution
Groovy_Demo Is the name of the project root directory ;
The mistake itself is simple , But it involves Java And Groovy Different path finding mechanisms ;
Java class JavaClass be located Groovy_Demo\src\main\groovy Under the table of contents , To be in the right place Java Call middle note in class Script.groovy Script ;
The full path must be used here “src/main/groovy/Script.groovy” , To find “Script.groovy” Script ;
Java In the class Groovy Script , Need to use “src/main/groovy/Script.groovy” route ;
import groovy.lang.Binding;import groovy.lang.GroovyShell;import java.io.File;import java.io.IOException;public class JavaClass {
public void startScript() throws IOException {
// Notice that you create groovy.lang.Binding Binding binding = new Binding(); // Set up args Parameter to Binding Medium variable Among members binding.setVariable("args", new String[]{
"arg0", "arg1"}); // perform Groovy Script GroovyShell shell = new GroovyShell(JavaClass.class.getClassLoader(), binding); File file = new File("src/main/groovy/Script.groovy"); shell.evaluate(file); } public static void main(String[] args) {
try {
new JavaClass().startScript(); } catch (IOException e) {
e.printStackTrace(); } }}And in the Groovy Call in script Another one Groovy Script , If two Groovy The script is in the same directory , You can use relative paths directly " Script.groovy " Call ;
Reference resources 【Groovy】Groovy Script call ( Groovy Another script is invoked. Groovy Script | Binding scope binding Variable analysis | Binding class variables Member analysis ) Blog source code ;
边栏推荐
- Web3为互联网带来了哪些改变?
- What about data leakage? " Watson k'7 moves to eliminate security threats
- 50. Pow(x, n). O(logN) Sol
- database mirroring
- Calculation method of boundary IOU
- IIC bus realizes client device
- A trip to Suzhou during the Dragon Boat Festival holiday
- Daily question brushing record (XIV)
- 微服務鏈路風險分析
- What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
猜你喜欢

Solutions for unexplained downtime of MySQL services

K210学习笔记(四) K210同时运行多个模型

科技云报道:算力网络,还需跨越几道坎?

数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖

Three "factions" in the metauniverse

Matlab draws a cute fat doll

Meituan dynamic thread pool practice ideas, open source

Oracle hint understanding

The Blue Bridge Cup web application development simulation competition is open for the first time! Contestants fast forward!

科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
随机推荐
CA certificate trampled pit
2022软件测试工程师涨薪攻略,3年如何达到30K
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
Blocking protocol for concurrency control
等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
Character conversion PTA
Leetcode simple question: find the nearest point with the same X or Y coordinate
Interview questions for famous enterprises: Coins represent a given value
Promql demo service
Storage optimization of performance tuning methodology
K210 learning notes (IV) k210 runs multiple models at the same time
50. Pow(x, n). O(logN) Sol
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Postman核心功能解析-参数化和测试报告
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
How to develop and introduce applet plug-ins
数博会精彩回顾 | 彰显科研实力,中创算力荣获数字化影响力企业奖
The simple problem of leetcode is to split a string into several groups of length K
如何向mongoDB中添加新的字段附代码(全)
Pinctrl subsystem and GPIO subsystem