0

I have two maven modules A and B for my project. The module A has a dependency with module B. In module B i am opening a file "user.txt" which i have kept under resources folder in module B.

Using Eclipse, i have work space dependency resolution enabled. When i run project A, it fails executing the method in module B. Error is that the file "user.txt" is not found. But the file is being searched under module A and not module B.

I tried to disable work space resolution, But the error persists. If i build the complete jar (A and B included) and run then the jar outside Eclipse, it is correctly located. Else i have to copy the file to module A as well to make it working in eclipse.

Any workaround?

Shabin Hashim
  • 677
  • 1
  • 10
  • 23

1 Answers1

1

Resources should not be loaded as files - where you need to use relative or absolute paths - but by asking the class loader for a resource. The official documentation is at http://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html

This is true for any Java project, not only Maven projects.

See Preferred way of loading resources in Java for details about how to get resource loading right.

Community
  • 1
  • 1
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347