Reputation: 534
I want to run a Java program using ssh, I've copied my private keys and I can run simple linux commands.
If run this command from the server I can see all the directories
ssh [email protected] pwd
However I want to run a Java jar app, like this:
ssh [email protected] java -Djava.library.path=myapp/. classpath=myapp/myapp.jar:. myClass
This is how I exactly run my app in the client machine:
java -Djava.library.path=myapp/. classpath=myapp/myapp.jar:. myClass
I got this error, obviously, java is installed
java: command not found
Upvotes: 2
Views: 4931
Reputation: 13110
Create a shell file and run that file over ssh using the following command:
ssh user@host "sh ~/app-start.sh"
Upvotes: 2
Reputation: 719416
The most likely problem is that the java
command is not on the command search path for the user
account.
Login to the client machine as user
, and type java -version
. If it says "command not found"
, that is indisputable evidence that java
is not on the user's command search path.
Login to the client machine using an account that you know can run java
. Now run java -version
to confirm that. Assuming that it works, run which java
to find the path for the java
command. (If it didn't work, then you are probably wrong about Java being installed. Or at leats ... about it being installed correctly.)
On the client machine, work out what the absolute path for the "myapp" directory is. Check that the "myapp" directory and its contents are readable by "user".
From the server, try running the app like this:
ssh [email protected] /path/to/java \
-Djava.library.path=/path/to/myapp \
-classpath /path/to/myapp/myapp.jar myClass
Notes:
java
is not on the user's command search path, use an absolute pathname for the java
command. In fact, it is advisable to use an absolute path anyway if you are concerned that the user might "alias" the java
command to something else.myapp
... to avoid problems with the user moving it, replacing it, etcetera..
on the classpath unless your Java app expects to be loading additional Java code out of the user's home directory.Obviously, java is installed ...
Why is it obvious?
How do you know that? Can you guarantee that for all client machines? Can you guarantee that "the user" won't mess with things?
Are you sure that Java is installed correctly? For example, that you have installed it in a place where it is on the "default" command search path for the user?
In a situation like this, you need to check / double-check all of your assumptions. Carefully. Methodically. The problem is typically something "face-palm obvious" that you have overlooked.
(It is human to make mistakes ... and counter productive to assume that you don't.)
Upvotes: 2