I'm working on a web application.
This is my project structure
src/
├── main
│ ├── java
│ ├── resources
│ └── webapp
└── test
├── java
└── resources
In my tests I want to call a method from a class in java
which uses a file in resources
.
So I want to know how to share my resources between main
and test
?
I don't want to copy files to test-resources
every time I edit them.
I tried SymLink but got an error 'Can't copy to test-classes
because file does not exist.`
And this is how I access a resource in case it matters
class.getResourceAsStream("/data.yml");
EDIT
So, apparently Maven do share resources between main and test by default but it's not the case here.
When I build I can see my resources from main
under target/classes
but nothing in target/test-classes
.
Files present in main
are visible in test
.
So you can put resources on the main tree if necessary for both tests and main.
If the resources are necessary only for the test put them on the test subtree.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With