I have:
Project
\-src/main/resources
\-src/main/java
\-src/test/resources
\-TestDataSourceContext.xml
\-src/test/java
and
DatabaseUtils
\-src/main/resources
\-src/main/java
\-src/test/resources
\-AbstractTestDataSourceContext.xml
\-src/test/java
In my Pom for Project I have a dependency as follows:
`
<dependencies>
<dependency>
<groupId>uk.co.domain.databaseutils</groupId>
<artifactId>DatabaseUtils</artifactId>
<version>${buildVersion}</version>
</dependency>
</dependencies>
Then in TestDataSourceContext.xml I have:
<import resource="classpath:AbstractTestDataSourceContext.xml"/>
Of course I get a filenotfoundexception when trying to do the import when running unit tests for Project, as AbstractTestDataSourceContext.xml is not included on the classpath. Is there a straightforward way of getting this file on the class path? Is there a maven option, a plugin etc? So when I depend on DatabaseUtils I can take all it’s resources, get DatabaseUtils to package it’s resource etc… I am still relatively new to Maven but it seems bizarre to me that this would be complicated to do.
What you usually do, you include another dependency with scope test:
It tells maven to include test-jar (should be called DatabaseUtils-<version>-tests.jar) on classpath for running tests (scope test).
This assumes there is a proper DatabaseUtils test jar available which should be the case if it’s installed in a default way by maven.