[英]How to add java library reference to a shell script
我在文件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依賴項。
由於在springClasspath
文件中有多個聲明,因此您打算在shell腳本中使用它們。 你需要它source
文件中的腳本,以進一步使用這些變量。
通過在腳本中獲取文件,可以使其中定義的變量在運行腳本的子外殼中可用。 例如,在將解釋器設置為bash
源之后,在start_order.sh
行中,腳本如下所示
#!/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
-ing該文件將不會在這種情況下工作, 除非你的源文件, 也是腳本,使他們在與設定的變量相同的父shell中運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.