@SpringBootTest
@RunWith(SpringRunner.class)
class TestFreemarkerApplicationTests {
@Test
public void getClassPath() {
//classpath = /C:/Program%20Files/Java/jdk-9.0.4/
String classpath = this.getClass().getResource("/").getPath();
//classpath = /D:/Program%20Files/Idea2017/IDEAProjects/test-freemarker/target/test-classes/com/example/testfreemarker/
// String classpath = this.getClass().getResource("").getPath();
System.out.println("classpath = " + classpath);
}
}
按理说,加了 / ,就应该获取的是 classpath
src/main下的classpath,就是 target/classes,对应Resources Root
src/test下的classpath,就是 target/test-classes,对应Test Resources Root
不加 / ,就是从当前类所在包下获取资源
但是我的输出,加了 / ,竟然是jdk的安装目录
不加 / ,在test-classes后又追加了当前类所在的包,都不对
最终目的就是获取 classpath,拼上templates/,确定test1.ftl模板的所在目录
因为用的是测试类
猜测要把src/main下的Resources Roo资源复制一份到src/test下,并标记为Test Resources Root
请问,哥 哥,姐 姐们
是我的知识有误,获取classpath的代码写错了?
还是IDEA配置的原因吗,若果是,怎么修改?