2017-06-16 164 views
0

在一些单元测试开始,我们用这样的资源链接,java.net.URL相对文件系统的URL规范

"https://<host name>/<project name>/pom.xml"

加载测试数据。但是,它在离线开发过程中不起作用。

如何在文件系统中指定相对于test/java文件夹URL?

我试图"file:///../pom.xml",但如果我指定"file://..\\pom.xml"它带给例外

java.io.FileNotFoundException: \..\pom.xml (The system cannot find the file specified)

我收到

Caused by: java.net.UnknownHostException: ..

+2

尝试'文件:../ pom.xml'。 – EJP

+0

阅读this。我想这就是你要找的。 –

回答

0

的答案是使用file:协议规范不按斜线。由于JUnit考虑作为根目录项目文件夹在我的情况正确链接到pom.xml很简单file:pom.xml