首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何根据操作系统在maven中设置环境变量

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

Stack Overflow用户
提问于 2013-10-16 20:42:20
回答 1查看 6.1K关注 0票数 4

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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-16 20:54:08

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

代码语言:javascript
复制
<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>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19413466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档