问题
I am using Maven Properties plugin to load the properties from a properties file. My Project is a multi module project with EAR and EJB modules with there respective pom files. And there is a parent pom. I am getting an error if I dont keep the properties file at all three locations (i.e. one in parent module and one each in EAR and EJB modules). It throws a FileNotFoundException if the Properties file isnt there even in one location. I dont want to keep the same file at three different locations. Please suggest how can I work around with this.
回答1:
Put the properties file at the parent project level, then tell the Properties Maven plugin to reference it from there.
<configuration>
<files>
<file>${myPropertyFile}/file>
</files>
</configuration>
In the parent project,
<properties>
<myPropertyFile>${project.basedir}/foo.properties</myPropertyFile>
</properties>
In the child projects,
<properties>
<myPropertyFile>${project.parent.basedir}/foo.properties</myPropertyFile>
</properties>
Depending on your project, you might be able to just put the latter ".parent." version in the parent project and be done with it, since the child projects would inherit it.
回答2:
In a production ready application you wouldn't want your properties to be bundled in your app, but rather be outside of it, so you can change just them rather than having to rebuild the whole app, so I would advise you to make your application production-ready and not have the properties included in the first place.
来源:https://stackoverflow.com/questions/21020755/maven-properties-plugin