Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Groovy Vert.x如何在模块中调用文件_Groovy_Vert.x - Fatal编程技术网

Groovy Vert.x如何在模块中调用文件

Groovy Vert.x如何在模块中调用文件,groovy,vert.x,Groovy,Vert.x,我有一个这样的模块结构: module_root/ mod.json filestore/myfile com/my/www/my.groovy(Compiled to my.class) 我想在my.groovy中调用filestore/myfile。我尝试了许多方法来访问该文件,但失败了 首先,我尝试使用相对路径。../../../filestore/myfile和filestore/myfile都失败。没有这样的文件或目录 然后我尝试使用绝对路径,我不知道如何获得

我有一个这样的模块结构:

module_root/
    mod.json
    filestore/myfile
    com/my/www/my.groovy(Compiled to my.class)
我想在my.groovy中调用filestore/myfile。我尝试了许多方法来访问该文件,但失败了

首先,我尝试使用相对路径。../../../filestore/myfile和filestore/myfile都失败。没有这样的文件或目录

然后我尝试使用绝对路径,我不知道如何获得模块的绝对路径。我尝试使用以下代码获取my.groovy路径:

scriptFile = getClass().protectionDomain.codeSource.location.path
但当我执行vertx runzip mymodule.zip时,我得到一个异常:

java.lang.NullPointerException: Cannot get property 'location' on null object

如何做到这一点?

对我来说这很有效。请让我知道是否适合您:

this is js, I don't know groovy but I suppose than must be similar
var CURRENT-DIRECTORY = new java.io.File("").getAbsolutePath()
然后可以使用字符串连接

CURRENT-DIRECTORY+"/filestore/myfile/mysuperFile.groovy" <--notice the / 

祝你好运

你试过/filestore/myfile了吗?ie:getClass.getResourceAsStream'/filestore/myfile.textHi@tim_-yates。我遵循了您的代码,但引发了一个异常:java.lang.NullPointerException:无法获取null对象的属性“text”
CURRENT-DIRECTORY+"/filestore/myfile/mysuperFile.groovy" <--notice the / 
return response.toString()