nerdexam
CompTIA

XK0-005 · Question #383

A Linux administrator is running a script that runs a Java application but receives the following error: Error: Java_Home is not set Java is installed on the Linux server and java -version returns a…

The correct answer is D. Set JAVA_HOME -which java. The Java application is failing because the JAVA_HOME environment variable is not set, even though Java itself is installed.

Troubleshooting

Question

A Linux administrator is running a script that runs a Java application but receives the following error:

Error: Java_Home is not set Java is installed on the Linux server and java -version returns a value. Which of the following should the administrator add to the script to resolve this issue?

Options

  • AExport PATH-$PATH: $JAVA_HOME
  • BEcho `which java > $JAVA_HOME
  • CExport Java_Home which java
  • DSet JAVA_HOME -which java

How the community answered

(31 responses)
  • A
    10% (3)
  • B
    6% (2)
  • C
    3% (1)
  • D
    81% (25)

Why each option

The Java application is failing because the JAVA_HOME environment variable is not set, even though Java itself is installed.

AExport PATH-$PATH: $JAVA_HOME

This option attempts to modify the `PATH` variable using incorrect syntax, not to set `JAVA_HOME`.

BEcho `which java > $JAVA_HOME

This option uses `echo` and redirection, which is not the correct command or syntax for setting an environment variable.

CExport Java_Home which java

This option has incorrect syntax for `export`, as it attempts to export `Java_Home` without an assigned value and then executes `which java` separately.

DSet JAVA_HOME -which javaCorrect

This option attempts to set the `JAVA_HOME` variable by referencing the `java` executable's location using `which java`, though the syntax `Set JAVA_HOME -which java` is an unconventional representation of standard shell commands like `export JAVA_HOME=$(which java)`.

Concept tested: Setting environment variables in Linux scripts

Source: https://docs.oracle.com/en/java/javase/17/install/installation-jdk-linux-platforms.html

Topics

#Environment Variables#Shell Scripting#Java Application Management#Linux Commands

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice