Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向shell脚本添加java库引用_Java_Bash_Shell_Unix - Fatal编程技术网

如何向shell脚本添加java库引用

如何向shell脚本添加java库引用,java,bash,shell,unix,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文件中有以下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\u order.sh,以便我的java程序引用所需的spring依赖项。我怎么做?

因为您计划在shell脚本中使用的
springClasspath
文件中有多个声明。您需要它来
source
脚本中的文件,以便进一步使用变量

通过在脚本中寻源文件,可以使其中定义的变量在运行脚本的子shell中可用。例如,在将解释器设置为
bash
后的
start\u 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
-在这种情况下,除非您将文件和脚本的源代码设置为与变量集在同一父shell中运行,否则将文件导出将不起作用。

springClasspath
是一个单独的文件吗?您想在其他脚本中使用其中定义的变量
CLASSPATH
?什么类型的文件是
CLASSPATH
除了变量初始化之外还有其他行吗?springClasspath是一个单独的文件。是的,我想在其他脚本中也使用CLASSPATH变量。springClasspath文件只包含库依赖项