4

I am using the maven exec plugin to run a simple java class. This java class loads a text file. Following the maven way, I have my text file inside:

src/main/resources

upon compilation, the resources ends up in:

target/classes

with the compiled sources. When I try to run:

maven exec:java

I get:

Caused by: java.io.FileNotFoundException: text.txt (The system cannot find the file specified)

This error goes away if I place text.txt in the ${basedir}, however this is not right because it is not following maven standards. Is there a way to configure this?

amaurs
  • 1,622
  • 1
  • 13
  • 18

1 Answers1

3

You should change code to read it from classpath as a Resource instead of reading it as File, maven executes java from your ${basedir} (where your pom resides)

and your code seems to attempt to look in current directory which is why it fails

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
  • Your link helped me solve my problem, thanks a lot, this explains how some times I was getting this error and sometimes everything worked fine. – amaurs Oct 17 '13 at 18:25