A maven project WEBAPP is a war packaging. It depends on the CORE project (jar packaging) Inside WEBAPP, i want to access resources under the src/main/resource dir from CORE project. Mvn clean install doesnt seem to put these CORE resources in the war classpath.
What do i need to specify in the poms to do this inclusion?
Maven does not include the jar dependency resources when building the war archive. The maven-remote-resources plugin is a way to achieve it. I was let to it by this SO question on copying resources
Just copy almost literally the example page of the plugin documentation. Resources I wanted to include in WEBAPP are located under src/main/resources/rulesproperties directory. In CORE pom.xml plugins section add :
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/rulesproperties/*</include>
</includes>
</configuration>
</plugin>
And in WEBAPP pom.xml plugin section, add
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>mvnGroupId:CORE:${project.version}</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
After a mvn clean install for the webapp project, the rulesproperties directory and its content is placed under the WEB-INF/CLASSES directory and correctly accessible as any other classpath resources.
Resources added to src/main/resource directory will by included in the resulting jar by default.
You can access them using:
this.getClass().getResource("yourFile");
And
this.getClass().getResourceAsStream("yourFile");
You can verify whether your resources are included in the jar by opening/extracting it manually (using a zip utility). Your resources should be located at the root of the jar file.
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