Invoking java jar from shell script in cloud foundry - java

I have a cloud foundry application which has shell exec(builder) through which i can execute shell scripts.
My cf application first downloads the shell script and java jar to CF local (ex:/app/lib/) directory from s3 and it executes the shell script.In shell script i am triggering a java program and it fails with "Shell command returned a non-zero exit value: 127 error" .
cat my_shell_java.sh ->
#!/bin/bash
java -jar myjar.jar com.abc.def.myClass
i have tried with below command as well but same error.
cat my_shell_java.sh ->
#!/bin/bash
$JAVA_HOME/bin/java java -jar myjar.jar com.abc.def.myClass
But if i execute shell which creates a folder in CF , it works fine.
cat my_shell_mkdir.sh ->
#!/bin/bash
mkdir /app/lib
Can some one pls help me on how can i execute a java program from shell script in Cloud foundry.

You can just push the java app archive using cf push.
What is the need for the shell script?
I am just curious....

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

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

Running selenium webdriver through jar file with upstart

i created a .jar executable file that when executed opens up two firefox selenium webdriver instances (two automated firefox instances) now when i execute the jar file through terminal likes this java -jar /opt/program.jar it works fine. but when i execute it through an upstart service:
program.conf
description "Desc"
author "Author"
start on filesystem
stop on shutdown
script
export HOME="/opt"
echo $$ > /var/run/program.pid
exec sudo /usr/bin/java -jar /opt/program.jar
end script
pre-start script
echo "[`date`] Starting" >> /var/log/program.log
end script
pre-stop script
rm /var/run/program.pid
echo "[`date`] Stopping" >> /var/log/program.log
end script
it doesn't launch any browser instances. just says
program start/running, process 14546
i would appreciate any help with how to go about doing what i am trying to do the correct way. thanks

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