[英]Set class path resource
我有一个问题宽度此代码:
final Map<String, File> attachments = new HashMap<>(); final Map<String, String> inlineResources = new HashMap<String, String>(); inlineResources.put("logo", "/res/img/IN_payoff.png"); for (File certificateFile : certificates) { attachments.put(certificateFile.getName(), certificateFile); } YadaEmailParam p = new YadaEmailParam(); p.inlineResources = inlineResources; yadaEmailService.sendHtmlEmail(p); }
这个错误:
org.springframework.mail.MailSendException: Failed messages: javax.mail.MessagingException: IOException while sending message; nested exception is: java.io.FileNotFoundException: class path resource [res/img/IN_payoff.png] cannot be opened because it does not exist
我如何设置课程路径?
如果这是一个Maven项目,则必须在src/main/resources
放入类路径中必须可用的src/main/resources
。
对于Maven项目,请将您的资源文件放在src/main/resources
目录中,因为它将最终出现在类路径中,并将自动包含在.jar文件中。 然后,您的资源将通过img/IN_payoff.png
路径进行访问。
另外,您可以使用pom.xml将目录添加到类路径中:
<build>
<resources>
<resource>
<directory>src/main/res</directory>
</resource>
</resources>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.