1

我的脚本更改为使用 sdkman 安装的 jdk,但未更改为本地脚本。如何使用 sdkman 在脚本中更改为我的本地 oracle 8 v261 jdk?

剧本

#!/bin/bash
. /usr/local/sdkman/bin/sdkman-init.sh
sdk ls java
for i in {"8_261-oracle", "9.0.4-open"}
do
  sdk u java $i
done

给出作为输出

[...]
               |     | 9.0.4        | open    | installed  | 9.0.4-open
               | >>> | 8.0.265      | open    | installed  | 8.0.265-open
               |     | 8.0.232      | open    | local only | 8.0.232-open
[...]
 Unclassified  |     | 8_261        | none    | local only | 8_261-oracle
================================================================================
Use the Identifier for installation:

    $ sdk install java 11.0.3.hs-adpt
================================================================================

Stop! java 8_261-oracle, is not installed.

Using java version 9.0.4-open in this shell.

我受到如何使用 SDKMAN 的启发!从脚本中安装包

4

1 回答 1

0

您可以解析 sdkman 的输出以检索已安装 sdks 的列表,如下所示:

#!/bin/bash

sdks=`sdk list java | grep installed | awk -F"|" '{print $6}'`

for sdk in ${sdks[@]}; do
  sdk use java $sdk
  ### YOUR CODE HERE
done

我省略了该. /usr/local/sdkman/bin/sdkman-init.sh部分,因为我建议按照 sdkman doc 中的建议在 bashrc/zshrc 中进行设置。

我的一个例子~/.zshrc

#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!!
export SDKMAN_DIR="$YOUR_PATH/.sdkman"
[[ -s "$YOUR_PATH/.sdkman/bin/sdkman-init.sh" ]] && source "$YOUR_PATH/.sdkman/bin/sdkman-init.sh"
于 2021-09-28T10:05:55.137 回答