I'm using Jcraft JSch to ssh into a remote machine and execute a command. As it's a non-interactive shell it's not finding Java home. How do I set Java home while using jsch? looking like
((ChannelExec) channel).setEnv("LANG", "UTF-8");
((ChannelExec) channel).setEnv("JAVA_HOME", "/blah/java/J8.0_64/");
is deprecated?
public String sendCommand(String command) {
  StringBuilder outputBuffer = new StringBuilder();
  try {
     Channel channel = sesConnection.openChannel("exec");
     ((ChannelExec) channel).setEnv("LANG", "UTF-8");
     ((ChannelExec) channel).setEnv("JAVA_HOME", "/blah/java/J8.0_64/");
     ((ChannelExec) channel).setCommand(command);
     InputStream commandOutput = channel.getInputStream();
     channel.connect();
     int readByte = commandOutput.read();
     while (readByte != 0xffffffff) {
        outputBuffer.append((char) readByte);
        readByte = commandOutput.read();
     }
     channel.disconnect();
  } catch (IOException ioX) {
     logWarning(ioX.getMessage());
     return null;
  } catch (JSchException jschX) {
     logWarning(jschX.getMessage());
     return null;
  }
  return outputBuffer.toString();
}
Error I'm getting while executing a command
JAVA_HOME not set and cannot find javac to deduce location, please set JAVA_HOME.
((ChannelExec) channel).setCommand(command);Could you edit your question to include an example of the actual command that you're trying to run here? - Kenster