linux - 如何根据操作系统在maven中设置环境变量

标签 linux windows maven

我对 maven 还很陌生。我已经设置了一个 pom.xml,它定义了一个用于运行我的单元测试的配置文件。我正在尝试设置 Path 环境变量。环境变量名称是 Windows 的 Path 和 Linux 的 LD_LIBRARY_PATH。我不想继续改变这些环境。取决于操作系统的变量名称。我该如何实现?

<profile>
        <id>integration-tests</id>
        <build>
         <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>${tychoVersion}</version>
                <configuration combine.self="override">
                    <argLine>${tycho.testArgLine} ${global.test.vmargs} ${bundle.test.vmargs}</argLine>
                    <forkMode>${bundle.test.forkMode}</forkMode>
                    <useUIHarness>${bundle.test.useUIHarness}</useUIHarness>
                    <useUIThread>${bundle.test.useUIThread}</useUIThread>
                    <environmentVariables>
                      <!--For windows change LD_LIBRARY_PATH to PATH-->
                        <LD_LIBRARY_PATH>${dependenciesDir}${path.separator}{env.LD_LIBRARY_PATH}</LD_LIBRARY_PATH>

                    </environmentVariables>
                </configuration>
            </plugin>
        </plugins>
        </build>

    </profile>

最佳答案

Profile activation可能在这里有所帮助。删除 <environmentVariables>来自集成测试配置文件的配置。然后添加下面的配置文件,调整 <activation>部分以满足特定要求。您不需要在命令行上显式启用这些配置文件; Maven 将根据正在运行构建的系统激活正确的配置文件。

<profile>
  <id>windows-tests</id>
  <activation>
      <os>
        <family>Windows</family>
      </os>
  </activation>
  <build>
     <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>${tychoVersion}</version>
            <configuration>
                <environmentVariables>
                    <PATH>${dependenciesDir}${path.separator}{env.PATH}</PATH>
                </environmentVariables>
            </configuration>
        </plugin>
    </plugins>
    </build>
</profile>
<profile>
  <id>linux-tests</id>
  <activation>
      <os>
        <family>Linux</family>
      </os>
  </activation>
  <build>
     <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-surefire-plugin</artifactId>
            <version>${tychoVersion}</version>
            <configuration>
                <environmentVariables>
                    <LD_LIBRARY_PATH>${dependenciesDir}${path.separator}{env.LD_LIBRARY_PATH}</LD_LIBRARY_PATH>

                </environmentVariables>
            </configuration>
        </plugin>
    </plugins>
    </build>
</profile>

关于linux - 如何根据操作系统在maven中设置环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19413466/

相关文章:

c++ - 控制台未聚焦时如何检测按键

windows - 通过本地路径访问文件或访问 UNC 共享路径在性能上是否存在差异

windows - 为什么堆栈低于内存中的文本?

java - Maven:未指定来源...但为什么呢?

linux - 德鲁帕尔 8 : How to use private file system for node

linux - 为什么芯片上的所有管脚都不是GPIO?

android - KR070PC7S LCD 显示器的 Linux 或 Android 驱动程序

linux - 如何在 apache/httpd 中创建 2 个站点

java - Maven 创建快速入门模板

android - 如何在 Eclipse 中安装 m2e-android-plugin?