如果os不是给定的系列(例如mac),如何激活pom.xml?

时间:2011-02-27 08:02:08

标签: java macos maven pom.xml tools.jar

来自Maven's website

    ...
  <profiles>
    <profile>
      <id>default-tools.jar</id>
      <activation>
        <property>
          <name>java.vendor</name>
          <value>Sun Microsystems Inc.</value>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>com.sun</groupId>
          <artifactId>tools</artifactId>
          <version>1.4.2</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
  ...

tools.jar已嵌入到Mac上,嵌入了classes.jar。有没有办法在激活设置中指定!mac(除了列出除mac之外的每个操作系统除外),而不是总是得到:

ERROR>warning: [path] bad path element ""/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/lib/tools.jar"": no such file or directory

2 个答案:

答案 0 :(得分:1)

你可以使用'!'激活的os部分中的修饰符(尝试并使用Maven 3.0.3)。使用与enforcer插件相同的算法,描述为here

<profiles>
    <profile>
        <id>not-mac</id>
        <activation>
            <os>
                <family>!mac</family>
            </os>
        </activation>
        <properties>
            <!-- Define non-mac properties here -->
        </properties>
    </profile>
</profiles>

有关在Maven中使用tools.jar的更完整说明,请参阅this article

答案 1 :(得分:0)

我发现了另一种方法。在“activeByDefault”配置文件中具有依赖关系。如果操作系统是mac,则有另一个配置文件(profile-2)被激活。根据{{​​3}},如果激活任何其他配置文件,“activeByDefault”配置文件将被停用。因此,如果操作系统是mac,则会激活profile-2,这将取消激活“activeByDefault”配置文件。