3 回答

TA贡献1824条经验 获得超8个赞
这就是配置文件的用途,提取属性的路径,为Windows,OSX等设置配置文件,并适当地定义属性值。
这是讨论操作系统配置文件的文档页面:Maven本地设置模型
它应该最终看起来像这样:
<profiles>
<profile>
<id>windows_profile</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>osx_profile</id>
<activation>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>

TA贡献1825条经验 获得超6个赞
感谢您向我介绍Maven个人资料。
我已经使用了如上所述的配置文件,并根据所需文件的存在来激活配置文件:
<profiles>
<profile>
<id>default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../lib/tools.jar</toolsjar>
</properties>
</profile>
<profile>
<id>mac-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
</profile>
</profiles>
我在前一篇文章中发布了此答案以强调一个错误:属性部分只能在激活部分中使用,以便基于指定属性的存在来激活配置文件。为了定义属性,必须像上面一样使用properties部分。

TA贡献1807条经验 获得超9个赞
嗨,我知道你们都很聪明,但是这让我花了几天的时间才弄清楚答案是不完整的-配置文件和依赖项都是必需的。我希望没有人会再浪费时间在这上面。请在下面查看我的完整代码:
<profiles>
<profile>
<id>osx_profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<os>
<family>mac</family>
</os>
</activation>
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
</properties>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
添加回答
举报