akshay1188
akshay1188

Reputation: 1667

Is it possible to execute commands remotely (ssh), through a Java program

I am looking to ssh into an Ubuntu Server via some (java) API. Is that even possible?

Here is what I am looking for exactly:

What I plan to do is provide some web client to start the emulator at the click of a button (considering everything is already set up i.e the Virtual Machine is up and running with the SDK installed).

I guess I need to execute the command to start the emulator. But is it possible to do this via some (java) API? I had a look into openstack4j and JClouds but could not find much. I tried to figure out it is using some ssh client library. Is that right?

Anything I am missing here?

Upvotes: 0

Views: 573

Answers (1)

Everett Toews
Everett Toews

Reputation: 10966

Have a look at this CloudServersPublish.java example, in particular the configureAndStartWebserver() method.

Also note how the SshjSshClientModule is added to the ComputeServiceContext in the constructor.

You'll also need to make sure you have the jclouds-sshj dependency.

<dependency>
  <groupId>org.apache.jclouds.driver</groupId>
  <artifactId>jclouds-sshj</artifactId>
  <version>1.9.0</version>
</dependency>

Upvotes: 1

Related Questions