如何将java库引用添加到shell脚本中

时间:2017-10-23 10:28:19

标签: java bash shell unix

我在文件springClasspath

中有以下spring引用jar
    CLASSPATH=/apps/cab/spring/spring-core-3.1.1.RELEASE.jar:/apps/cab/spring/commons-logging-1.2.jar:/apps/cab/spring/spring-aop-4.2.2.RELEASE.jar:/apps/cab/spring/spring-beans-4.2.2.RELEASE.jar 
export CLASSPATH

我想将springClasspath文件引用到我的shell脚本文件start_order.sh中,以便我的java程序引用所需的spring依赖项。我该怎么办?

1 个答案:

答案 0 :(得分:1)

由于您计划在shell脚本中使用springClasspath文件中有多个声明。您需要在source脚本中的文件中进一步使用变量。

通过在脚本中获取文件,您可以使其中定义的变量在运行脚本的子shell中可用。例如,在将解释器设置为start_order.sh之后的bash行中,脚本如下所示

#!/usr/bin/env bash

# Give the full path to the file if it is present in another location
. ./springClasspath 

# with the above source done, the variables can be used as below in your
# script
echo "$CLASSPATH"

请记住export - 文件在这种情况下无法正常工作,除非您的源文件而脚本以便它们运行在具有变量集的同一父shell中。