java文件的类路径

java文件的类路径,java,Java,我正在使用ogham API发送带有模板的电子邮件。 对于发送电子邮件,有一行类似于- service.send(new Email ("subject", new TemplateContent ("classpath:/template/thymeleaf/simple.html", new SimpleBean ("foo", 42)), "<recipient address>")); 我的类路径是什么? 我已经使用了“/template//parcio/Sig

我正在使用ogham API发送带有模板的电子邮件。 对于发送电子邮件,有一行类似于-

 service.send(new Email
 ("subject", 
 new TemplateContent
 ("classpath:/template/thymeleaf/simple.html", new SimpleBean
 ("foo", 42)), "<recipient address>"));
我的类路径是什么? 我已经使用了“/template//parcio/SignupEmailTemplate.html”。然后出错了


“模板可能不存在或不可访问”。

使用绝对路径定位文件,相对路径并不总是相对于源目录

使用绝对路径定位文件,相对路径不总是相对于源目录

使用

ClassLoader.getSystemResource("template/parcio/SignupEmailTemplate.html").toString()
要获取位于您的maven resources文件夹中的文件路径。

使用

ClassLoader.getSystemResource("template/parcio/SignupEmailTemplate.html").toString()
获取位于maven resources文件夹内的文件路径