我在文件 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 依赖项。我该如何执行此操作?
最佳答案
因为您计划在 shell 脚本中使用 springClasspath
文件中的多个声明。您需要它来来源
脚本中的文件以进一步使用变量。
通过在脚本中获取文件,您可以使其中定义的变量在运行脚本的子 shell 中可用。例如,在将解释器设置为 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"
记住导出
- 在这种情况下文件将不起作用,除非您提供文件和脚本的源代码,以便它们在设置了变量的同一父 shell 中运行。
关于java - 如何将 java 库引用添加到 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46887178/