我正在用Wiremock运行一个spring boot应用程序。 我的文件结构如下:
project/main/
- java/package/Wiremock.java
- resources/wiremock/__files/file.json
在Wiremock.java内部,我像这样调用WireMockServer:
WireMockServer wiremockServer = new WireMockServer(WireMockConfiguration.wireMockConfig()
.withRootDirectory(getClass().getResource("/wiremock").getPath())
.port(port));
wiremockServer.start();
wiremockServer.stubFor(get(urlEqualTo("/myurl"))
.willReturn(aResponse()
.withBodyFile("file.json")
.withHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE)
.withStatus(HTTP_OK)));
当我在本地运行它时,它的工作就像预期的那样。
当我将应用程序编译为jar文件时,将生成一个jar文件/users/user/project-0.0.1-snapshot.jar,其结构如下:
BOOT-INF/classes/
- wiremock/__files/file.json
- package/Wiremock.class
但是当我运行jar文件时,我得到以下错误:
java.lang.RuntimeException: java.io.FileNotFoundException: /Users/user/jar:file:/Users/user/project-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/wiremock/__files/file.json (No such file or directory)
请帮忙,谢谢
如果这条路是正确的?
/users/user/jar:file:/users/user/project-0.0.1-snapshot.jar!/boot-inf/类!/wiremock/__files/file.json(没有这样的文件或目录)
我发现还有一个“!” 在xxxx.jar和classess之后。