简体   繁体   中英

Set class path resource

i have a problem width this code:

 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); } 

This error:

 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 

How i can set class path?

如果这是一个Maven项目,则必须在src/main/resources放入类路径中必须可用的src/main/resources

In case of Maven project, put your resource files in src/main/resources directory, as it will end up on classpath and will be automatically included in .jar file. Then your resource will be accessible by img/IN_payoff.png path.

Alternatively, you can add your directory to classpath with pom.xml:

<build>
    <resources>
        <resource>
            <directory>src/main/res</directory>
        </resource>
    </resources>
 </build>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM