我有一个包含多个maven模块的项目
project/pom.xml
/external_services/pom.xml
/ifs/pom.xml
/src/test/java/
/MockIFSClient.java
/IFSClientTest.java
/src/test/java/resources/sample.json
/inventory/pom.xml
/business/pom.xml
/src/main/java/InventorySummary.java
/services/pom.xml
/src/main/java/InventorySummaryResource.java
/src/main/test/InventorySummaryResourceTest.java
MockIFSClient访问sample.json为
try {
inventoryPriceDetails = mapper.readValue(new File(getClass().getResource("/getInventoryAndPriceResponse.json").getPath()), new TypeReference>() {
});
} catch (final IOException e) {
throw new RuntimeException("could not read resource :" + e.getMessage());
}
所以IFSClientTest运行鳍,因为它们在同一个包中.
问题?
InventorySummaryResourceTest调用MockIFSClient,它试图访问相同的代码,但现在它失败了
could not read resource :file:/Users/harith/IdeaProjects/inventory_api/external_services/ifs/target/ifs-1.0-SNAPSHOT-tests.jar!/sample.json (No such file or directory)
services / pom.xml具有依赖性
com.org.project.external_services
ifs
${project.version}
test-jar
test
题
我做了什么改变
new File(getClass().getResource("/getInventoryAndPriceResponse.json").getPath())
这样它也可以从不同的模块访问