FileNotFoundException in test case run with maven using Spring resource loader

Our program is sending mails. For sending mails it includes an attachment.

The project is set up with maven. The JUnit test case loads the spring configuration first. Spring is loading the File with its DefaultResourceLoader. When running this directly within the workspace its running fine, however as a maven test it fails.

Spring Configuration for resource loader:

<property name="defaultResourceLoader">
    <bean class="" />


public class SomeClassA {

     private DefaultResourceLoader defaultResourceLoader; 

     private String mailLogo; 

     public void someMethod(){
         String filePath = defaultResourceLoader.getResource(mailLogo).getFile().getAbsolutePath();   

The exception points to the actual problem and difference: class path resource [templates/efmaillogo.jpg] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/IBM/workspace/efMy10/ef-mvxsrv-reactor/ef-mvxsrv-service-resources/target/ef-mvxsrv-service-resources-1.5.23-SNAPSHOT.jar!/templates/efmaillogo.jpg at org.springframework.util.ResourceUtils.getFile( at at SomeClassA.someMethod(

Spring tries to look the file up within the jar. When running it as a junit test within eclipse, everything is working, because spring finds the file directly within the workspace. However when running the same unit test with maven it fails, because it doesn't find the file, because its in a jar in a different module. The file in the other module is needed by different modules, so I don't want to move it. On the application server where everything is deployed its working as well, because the .ear file is expanded.

I'm wondering if there is a different way to access the file with Spring, so that I don't have to skip this test case with maven.

Update Tried doing a lookup for the file with:

 String filePath = defaultResourceLoader.getResource(mailLogo).getURL.getFile();

However it now fails when actually sending the mail with Transport.send(msg). file:\C:\Users\uhe.m2\repository\com\clavisit\ef\mvxsrv\ef-mvxsrv-service-resources\1.5.23-SNAPSHOT\ef-mvxsrv-service-resources-1.5.23-SNAPSHOT.jar!\templates\efmaillogo.jpg (The filename, directory name, or volume label syntax is incorrect.) at com.sun.mail.smtp.SMTPTransport.sendMessage( at javax.mail.Transport.send0( at javax.mail.Transport.send( at com.clavisit.ef.ep.service.integration.handler.mail.SendMail.sendMessage(


String filePath = defaultResourceLoader.getResource(mailLogo).getURL().getFile();

The above code change must work as per the discussion in this thread

Need Your Help

Passing the url in a link not working


I'm trying to pass the id of a blogpost in an url. It works in the adminpanel (read blogpost) now I want to do the same on my frontpage, so that it says read more under every blogpost, but when I u...

Trying to reverse the contents of the file and reverse the file's name into a new file?

c++ binary reverse fstream ifstream

So here's my code, but I don't know how to make the new file's name the original file's name reversed.