使用 grails-3.3.1 开发项目并生成 Runnable WAR 文件。当我使用命令运行时:
java -jar build/libs/myproject-0.1.war
它正在返回null
以下行:
serveltContext.getRealPath("/someSource");
但是当部署在 Tomcat 容器中时它工作正常。
然后尝试了以下方法:
servletContext.getResource("someSource").getPath();
它正在返回,但不是预期的,也不是getRealPath()
返回的。它是这样返回的:
D:/myprojects/myproject/build/libs/myproject-01.war*/
这对我没有用。找到建议使用getResourceAsStream()
但我不想要资源的答案,我只想要String
.