【问题标题】:What is workingDirectory in Maven POM.xml?Maven POM.xml 中的 workingDirectory 是什么?
【发布时间】:2018-04-03 13:16:21
【问题描述】:

想了解在 Maven POM.xml 中使用什么以及为什么使用标签。标签的意义是什么?

例子:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <showDeprecation>true</showDeprecation>
                <compilerVersion>1.8</compilerVersion>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <workingDirectory>target/</workingDirectory>
            </configuration>
        </plugin>

【问题讨论】:

  • 你能展示你的 pom 的例子吗?它可能是插件的特定选项。
  • 很遗憾,pom 文件中不存在 workDirectory 这样的标签:maven.apache.org/pom.html
  • 添加了一个使用的例子。
  • 不幸的是,我在 Maven 编译器插件文档中也找不到类似 workingDirectory 的内容? maven.apache.org/plugins/maven-compiler-plugin/…你在哪里找到的?

标签: maven maven-3 pom.xml


【解决方案1】:

默认情况下,Maven POM 中没有 workingDirectory 元素,有关可以在 POM 中使用的元素的详细信息,请参阅 Maven POM reference

但是,workingDirectory 可以存在于某些插件配置中,例如Maven Exec Plugin 上的exec:exec 目标,例如:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.6.0</version>
    <executions>
      <execution>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <executable>java</executable>
      <workingDirectory>target/</workingDirectory>
      <arguments>
        <argument>-classpath</argument>
        <classpath>
          <dependency>commons-io:commons-io</dependency>
          <dependency>commons-lang:commons-lang</dependency>
        </classpath>
        <argument>com.example.Main</argument>
      </arguments>
    </configuration>
  </plugin>

将从target 目录执行java。但是,像您的示例中那样在编译器插件中添加workingDirectory 不会做任何事情 - 没有这样的配置。

【讨论】:

    猜你喜欢
    • 2012-05-16
    • 2012-05-16
    • 1970-01-01
    • 2021-09-10
    • 2021-04-18
    相关资源
    最近更新 更多