Run Jar file in command prompt on Linux Server - java

How can we run Jar File in command prompt?
I've used this command:
java -jar myJARFile.jar
But the result was:
-bash: java: command not found

You need to install java on your machine and add the java directory to PATH variable.

Related

How to run jar files sequentially from a shell script

I am trying to run two java application one after other in my docker container.
In my dockerfile i have specified invoker.sh as the entry point.
ENTRYPOINT ["sh", "/opt/invoker.sh"]
Then i use this script to run two jar files.
#!/bin/sh
java -jar loader.jar
java -jar service.jar
but this does not work. It gives
Error: Unable to access jarfile javaimpl-loader.jar
and only the service.jar is executed. When i tried echo $(ls) it shows that both the jar files are there.
but if i change the script to
#!/bin/sh
echo $(java -jar loader.jar)
java -jar service.jar
then both the jars work. Why cant i use the 1st script. any help regarding this highly apreciated.
It appears the first example is being treated as a single line, you could work with that. Also, I would prefer bash to /bin/sh. Like,
#!/usr/bin/env bash
java -jar loader.jar && java -jar service.jar

Where does the Jenkins Windows installer put java?

I installed the Jenkins MSI sliently
c:\windows\temp\jenkins.msi /qn /L*V c:\windows\temp\jenkins.log
Seems to be running OK, but it appears java is not in the system PATH. Where does the MSI put java?
Edit:
I'm asking this because I want to install plugins like this:
java -jar jenkins-cli.jar -s http://127.0.0.1:8080/ install-plugin http://updates.jenkins-ci.org/download/plugins/aws-lambda/0.5.5/aws-lambda.hpi
I can't run this command because I don't know where to java exe is
It puts it here: 'C:\Program Files (x86)\Jenkins\jre\bin\java.exe'

Can run jar from commandline but not in shell script - why?

I want t start a jar which should provide a Rest-WebService.
When I run following command from terminal the jar and the webservice starts successfully:
java -jar SchnittprofilService-1.0-fat.jar BH121 8888
If I run the same command in a shell script start.sh, the jar starts but the not the webservice.
The permission for start.sh is set to 777.
Any suggestions?
Oops:
You have to put your arguments in quotation marks:
java -jar SchnittprofilService-1.0-fat.jar "BH121" "8888"

I want to make sh file that execute jar file directly in Ubuntu 12.04LTS

In Ubuntu 12.04 (Not Working)
I create a sh file and write the code.
#echo off
java -jar Program.jar
also allow the permission of execution.
But no action performed. While in windows it works fine.
In Windows 7 (Working)
I create a batch file and write the code.
#echo off
java -jar Program.jar
Please help what i am doing wrong.
Ubuntu shell scripts can't use #echo off that's for DOS command scripts. You need something like,
#!/bin/sh
java -jar Program.jar
The first line is known as the Shebang (the #! is a kind of magic number).

Multiple commands on remote machine using shell script

I have a Java program Desktop/testfolder/xyz.jar on a remote machine. It has a configuration file on the same folder. When I SSH into the machine, I do:
"ssh user#remote java -cp Desktop/testfolder/xyz.jar Main"
The problem here is the configuration file is not in the path, as we are in the home folder so my program cannot read the configuration.
I want to first go into that folder and then run the program from that folder. In a shell script if I did this
"ssh user#remote cd Desktop/testfolder"
"java -cp xyz.jar Main"
it executes the first statement and when the second statement is run it runs on my current machine not the remote machine.
Can we do only one command or there are any other solutions for this?
Try something like this:
ssh you#yours.com "cd /home && ls -l"
You could try separating the commands by a semicolon:
ssh user#remote "cd Desktop/testfolder ; java -cp xyz.jar Main"
If you want to split your commands over multiple lines for the sake of readability, you could also pass the list of commands to the bash command as follows:
ssh user#remote.host bash -c "'
cd Desktop/testfolder
java -cp xyz.jar Main
'"

Categories

Resources