Can I run a java jar program with ssh?











up vote
1
down vote

favorite












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 user@192.168.1.2 pwd


However I want to run a Java jar app, like this:



ssh user@192.168.1.2 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









share|improve this question






















  • Is java installed? What is the output of this command java -version
    – Nicholas K
    Nov 20 at 13:01












  • Is java installed at the location you think it is?
    – Teun van der Wijst
    Nov 20 at 13:03






  • 3




    Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
    – Michael
    Nov 20 at 13:05

















up vote
1
down vote

favorite












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 user@192.168.1.2 pwd


However I want to run a Java jar app, like this:



ssh user@192.168.1.2 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









share|improve this question






















  • Is java installed? What is the output of this command java -version
    – Nicholas K
    Nov 20 at 13:01












  • Is java installed at the location you think it is?
    – Teun van der Wijst
    Nov 20 at 13:03






  • 3




    Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
    – Michael
    Nov 20 at 13:05















up vote
1
down vote

favorite









up vote
1
down vote

favorite











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 user@192.168.1.2 pwd


However I want to run a Java jar app, like this:



ssh user@192.168.1.2 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









share|improve this question













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 user@192.168.1.2 pwd


However I want to run a Java jar app, like this:



ssh user@192.168.1.2 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






java ssh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 13:00









araujo

359




359












  • Is java installed? What is the output of this command java -version
    – Nicholas K
    Nov 20 at 13:01












  • Is java installed at the location you think it is?
    – Teun van der Wijst
    Nov 20 at 13:03






  • 3




    Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
    – Michael
    Nov 20 at 13:05




















  • Is java installed? What is the output of this command java -version
    – Nicholas K
    Nov 20 at 13:01












  • Is java installed at the location you think it is?
    – Teun van der Wijst
    Nov 20 at 13:03






  • 3




    Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
    – Michael
    Nov 20 at 13:05


















Is java installed? What is the output of this command java -version
– Nicholas K
Nov 20 at 13:01






Is java installed? What is the output of this command java -version
– Nicholas K
Nov 20 at 13:01














Is java installed at the location you think it is?
– Teun van der Wijst
Nov 20 at 13:03




Is java installed at the location you think it is?
– Teun van der Wijst
Nov 20 at 13:03




3




3




Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
– Michael
Nov 20 at 13:05






Java's not on the path then. Use ssh user@192.168.1.2 /path/to/java -Djava.lib...
– Michael
Nov 20 at 13:05














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










The most likely problem is that the java command is not on the command search path for the user account.




  1. 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.


  2. 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.)


  3. 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".



  4. From the server, try running the app like this:



      ssh user@192.168.1.2 /path/to/java 
    -Djava.library.path=/path/to/myapp
    -classpath /path/to/myapp/myapp.jar myClass


    Notes:




    • If 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.

    • Use absolute paths for the installation of myapp ... to avoid problems with the user moving it, replacing it, etcetera.

    • The syntax for the classpath option is different to what you showed us

    • You shouldn't have . 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.)






share|improve this answer























  • Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
    – araujo
    Nov 20 at 15:55













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393563%2fcan-i-run-a-java-jar-program-with-ssh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










The most likely problem is that the java command is not on the command search path for the user account.




  1. 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.


  2. 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.)


  3. 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".



  4. From the server, try running the app like this:



      ssh user@192.168.1.2 /path/to/java 
    -Djava.library.path=/path/to/myapp
    -classpath /path/to/myapp/myapp.jar myClass


    Notes:




    • If 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.

    • Use absolute paths for the installation of myapp ... to avoid problems with the user moving it, replacing it, etcetera.

    • The syntax for the classpath option is different to what you showed us

    • You shouldn't have . 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.)






share|improve this answer























  • Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
    – araujo
    Nov 20 at 15:55

















up vote
1
down vote



accepted










The most likely problem is that the java command is not on the command search path for the user account.




  1. 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.


  2. 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.)


  3. 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".



  4. From the server, try running the app like this:



      ssh user@192.168.1.2 /path/to/java 
    -Djava.library.path=/path/to/myapp
    -classpath /path/to/myapp/myapp.jar myClass


    Notes:




    • If 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.

    • Use absolute paths for the installation of myapp ... to avoid problems with the user moving it, replacing it, etcetera.

    • The syntax for the classpath option is different to what you showed us

    • You shouldn't have . 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.)






share|improve this answer























  • Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
    – araujo
    Nov 20 at 15:55















up vote
1
down vote



accepted







up vote
1
down vote



accepted






The most likely problem is that the java command is not on the command search path for the user account.




  1. 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.


  2. 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.)


  3. 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".



  4. From the server, try running the app like this:



      ssh user@192.168.1.2 /path/to/java 
    -Djava.library.path=/path/to/myapp
    -classpath /path/to/myapp/myapp.jar myClass


    Notes:




    • If 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.

    • Use absolute paths for the installation of myapp ... to avoid problems with the user moving it, replacing it, etcetera.

    • The syntax for the classpath option is different to what you showed us

    • You shouldn't have . 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.)






share|improve this answer














The most likely problem is that the java command is not on the command search path for the user account.




  1. 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.


  2. 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.)


  3. 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".



  4. From the server, try running the app like this:



      ssh user@192.168.1.2 /path/to/java 
    -Djava.library.path=/path/to/myapp
    -classpath /path/to/myapp/myapp.jar myClass


    Notes:




    • If 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.

    • Use absolute paths for the installation of myapp ... to avoid problems with the user moving it, replacing it, etcetera.

    • The syntax for the classpath option is different to what you showed us

    • You shouldn't have . 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.)







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 13:46

























answered Nov 20 at 13:34









Stephen C

511k69560912




511k69560912












  • Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
    – araujo
    Nov 20 at 15:55




















  • Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
    – araujo
    Nov 20 at 15:55


















Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
– araujo
Nov 20 at 15:55






Thank you! That worked. As I wrote, java was obviously installed :) I'm just kidding. Thanks
– araujo
Nov 20 at 15:55




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393563%2fcan-i-run-a-java-jar-program-with-ssh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen