MAC OS Maven:无法识别导出的环境变量

时间:2018-05-08 14:38:35

标签: bash macos shell maven environment-variables

我想使用shell脚本构建maven项目。考虑场景

在我的项目中,我有一些测试,例如

public class MyTest{

  @Before
  public void setUp() {
   String libPath = System.getenv("LIBRARY_PATH");
    if (libPath == null || libPath.isEmpty()) {
      logger.error(
          "LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded");
      throw new IllegalArgumentException(
          "LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded");
    }
    logger.info("LIBRARY_PATH found. All the binaries will be loaded from here {}", libPath);
}
/*Some tests that depend on LIBRARY_PATH being set*/
} 

现在,我有一个shell脚本build_project执行以下操作

#!/bin/bash -e

if [ -z $1 ] ; then
    echo "Must provide LIBRARY_PATH"
    exit 1
fi

source setup_work.sh $1

mvn clean install

这是setup_work.sh脚本

#!/bin/bash -e

export LIBRARY_PATH=$PWD/$1
echo "LIBRARY_PATH is ${LIBRARY_PATH}"
# some other setup tasks specific to my project

最后,我所做的只是运行

build_project.sh /some/path/

它在linux / ubuntu上完全正常

但是,它不适用于MAC OS。我明白了

LIBRARY_PATH is workingDir/some/path/
/*
lots of maven messages
.
.
.
*/
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running my.project.package.MyTest
[ERROR] LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded
IllegalArgumentException

问题在于maven还是MAC OS?为什么我无法从shell脚本中导出env变量?

最后请注意,如果我在bash_profile

中添加以下内容

export LIBRARY_PATH=some/path/i/need

然后它适用于MAC OS。这让我相信问题在于MAC OS。

我做错了什么?

0 个答案:

没有答案