当前位置:网站首页>[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 ;
边栏推荐
- Leetcode simple question: the minimum cost of buying candy at a discount
- Ad637 notes d'utilisation
- K210 learning notes (IV) k210 runs multiple models at the same time
- Leetcode simple question ring and rod
- 700. Search in a Binary Search Tree. Sol
- AD637 usage notes
- FBO and RBO disappeared in webgpu
- Metaverse Ape获Negentropy Capital种子轮融资350万美元
- Storage optimization of performance tuning methodology
- 1.3 years of work experience, double non naked resignation agency face-to-face experience [already employed]
猜你喜欢

Blocking protocol for concurrency control

PyGame practical project: write Snake games with 300 lines of code

Countdown to 92 days, the strategy for the provincial preparation of the Blue Bridge Cup is coming~

Wonderful review of the digital Expo | highlight scientific research strength, and Zhongchuang computing power won the digital influence enterprise award

2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*

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

A number of ventilator giants' products have been recalled recently, and the ventilator market is still in incremental competition

Overview of concurrency control

Depth first DFS and breadth first BFS -- traversing adjacency tables

Database tuning solution
随机推荐
AD637 usage notes
[Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
MySQL actual combat 45 lecture learning (I)
The American Championship is about to start. Are you ready?
Matlab draws a cute fat doll
Bitbucket installation configuration
Serializability of concurrent scheduling
Business learning of mall commodity module
笔记本电脑蓝牙怎么用来连接耳机
How to add new fields to mongodb with code (all)
Stored procedures and stored functions
Daily question brushing record (XIV)
Kubernetes Administrator certification (CKA) exam notes (IV)
database mirroring
Official clarification statement of Jihu company
微服务链路风险分析
Leetcode simple question: the minimum cost of buying candy at a discount
What about data leakage? " Watson k'7 moves to eliminate security threats
Common interview questions of redis factory
How to develop and introduce applet plug-ins