How to execute a JAR file from Jenkins?
I have a JAR output from a gradle build section, i want to execute this JAR file after it created. I am using a Jenkins platform setup in windows server. I don't have any separate node for execution, master itself acts as both server and node.
Tried several ways but not working as expected. The JAR file is working if i run in a normal windows batch command window but the same command is not working if i executed it from a Jenkins windows batch command build section.
Any help would be appreciated.
The following commands in the post build script started working. The first command will kill the running instance of the JAR and start the new instance as well.
for /f "tokens=1" %%i in ('jps -m ^| find "%BIN_JAR_NAME%"') do ( taskkill /F /PID %%i ) start java -jar -Dspring.profiles.active=**** %OUTPUT_PATH%\%BIN_JAR_NAME%
Related
I want to run a jar as a background process on a remote machine over ssh connection. There is bash script on remote machine to execute jar
#!/bin/sh
export JAVA_HOME=/location/of/java/
export PATH=$JAVA_HOME/bin:$PATH
nohup java -jar jar_name.jar config.properties &
If I execute the above script directly from remote machine(sudo ./start_script.sh), jar is started as background process and stdout is directed to nohup.out in the same folder as jar. But when I run script from local machine : ssh vm_name 'sudo ./start_script.sh', the process starts up. but it blocks and the output is directed to local terminal.
is there way to achieve this?
EDIT: I need to run script as root and also pass parameters to script, added placeholder path for JAVA_HOME to avoid confusion
You need to tell the ssh to connect as a terminal.
ssh vm_name -t 'sudo ./start_script.sh'
It's likely recognizing that you are not on as a terminal and altering behavior accordingly.
Same issue related here:
https://serverfault.com/questions/955268/what-is-the-difference-between-running-a-command-in-ssh-shell-manually-vs-runnin
Try
$ ssh user#host bash -l ./build.sh
i search a way to start a jar on a raspberry pi. In need to start the jar as root because the jar set gpios and this is only possible as root user.
The jar is a GUI fullscreen application. This i tried already:
Create a Crontab (contab -e, #reboot, don't work because the application is a gui application)
By adding a file called /etc/xdg/autostart/RPi-infoscreen.desktop
[Desktop Entry]
Type=Application
Name=RPi-infoscreen
Comment=Keysystem
NoDisplay=false
Exec=/usr/bin/lxterminal -e /home/pi/keySys.sh
NotShowIn=GNOME;KDE;XFCE;
The command line program is at /home/pi/keySys.sh
#!/bin/bash
cd /home/pi/Key
sudo java -jar keyTest.jar
Make it executable:
chmod +x /home/pi/keySys.sh
This had worked for me first. But than i had to change it because i need to see the exception from the terminal. So i changed the command line program what is at /home/pi/keySys.sh to:
#!/bin/bash
cd /home/pi/Key
sudo java -jar keyTest.jar 2> errorOutput.log > output.log &
Since this time nothing worked anymore. I changed it back to sudo java -jar keyTest.jar but it don't start the application anymore. I make it executable again but nothing happened.
Have someone a idea?
Thank you very much!
I am very newbie in Jenkins, I've created Jenkins job where it will execute somekind like this jar command in Jenkins job:
ECHO **********************************
ECHO Upgrade Devices
ECHO **********************************
cd c:\JenkinsPull
java -jar DevicesUpgrade.jar PC1 %ProjectName%
When I start to build the Jenkins job it able to run the DevicesUpgrade.jar file until last part of jar process before it finish, sudddenly it just stuck there till I abort the job.
So I think there must be a bug inside the jar file, but it is weird because after that, I tried to run java -jar DevicesUpgrade.jar PC1 %ProjectName% on command prompt, it didn't stuck at all and it able to finish up the jar.
Is there anything that I need to do on Jenkins to fix this hang problem?
Here is the output I got from Jenkins:
c:\JenkinsPull>java -jar DevicesUpgrade.jar PC1 lex_l11_gms
%%%%f95eac91%%%%%
lexl11g_64-ota-L11_D01.00.48_userdebug.zip
1517844524458
%%%%%%%%%%%%%%%%%%%%%%%%
adb -s shell f95eac91 "getprop | grep ro.build.version.incremental"
\\ANDROIDTEST-05\ARM_png\JenkinsPull\BSP\lex_l11_gms\lexl11g_64-ota-
L11_D01.00.48_userdebug.zip
1.143848721E9
[*--------------------------------------------------------------------------
--------------------------]
Here it keep loading the jenkins job till I need to abort the Jenkins job.
Here is the output I got when I am running the jar via Command Prompt:
c:\JenkinsPull>java -jar DevicesUpgrade.jar PC1 lex_l11_gms
%%%%f95eac91%%%%%
lexl11g_64-ota-L11_D01.00.48_userdebug.zip
1517844524458
%%%%%%%%%%%%%%%%%%%%%%%%
adb -s shell f95eac91 "getprop | grep ro.build.version.incremental"
\\ANDROIDTEST-05\ARM_png\JenkinsPull\BSP\lex_l11_gms\lexl11g_64-ota-
L11_D01.00.48_userdebug.zip
1.143848721E9
[*--------------------------------------------------------------------------
--------------------------]
Upgrade Device Completed..!!
c:\JenkinsPull>
java -jar /home/scripts/relay.jar is working fine when I launch from command line. The command produces a file: relay.txt
In crontab
/usr/bin/java -jar /home/oneprovider/relay.jar
is not producing anything. I first had it without /usr/bin/ but then did which java and added absolute path with no luck. The jar file was originally written for windows but it works in Linux fine when launched from command line
What am I missing?
Agreed that the working directory is likely the problem. Can you write a shell script that wraps the java invocation and sets the working directory? Something like:
#!/bin/sh -e
cd /home/oneprovider
/usr/bin/java -jar /home/oneprovider/relay.jar
Then change the cron job to run the script instead. Remember to chmod it and make sure that the cron user can write to the directory if it isn't your personal crontab.
I am not familiar with batch script, but I want to create a Windows Batch File to start a Java program. The problem is that it has to specific the path where JRE is installed. When you install both JRE7 and JRE8, the name of that JRE8 folder would call something like jre1.8.0_20 or jre1.8.0_40 with the version number in the back. When you have only JRE8 installed, the folder would call jre8. Is there an easier way to find where the most updated JRE installed and then execute it? Thanks.
start ..\..\Java\jre7\bin\javaw.exe -Xms512M -Xmx1024M -Djna.library.path=.\lib -cp example.jar; com.example.main
You should be able to get the location of javaw.exe by executing where java. This can be set as a variable inside a batch file like this:
# sets a variable called 'java' to the location of javaw.exe
for /f "delims=" %a in ('where javaw') do #set java=%a
# execute you jar file
%java% -jar <app.jar>
Noticed that the above only seems to work when running directly from the command line. Here is another example that should work in a batch file:
# run.bat
#echo off
setlocal enabledelayedexpansion
for /f %%a in ('where javaw') do (
set java=%%a
)
!java! -jar %1
The above batch file should be called with the name of the jar file:
run.bat app.jar
I think it's best to just user JAVA_HOME and/or JRE_HOME and let the user / sysadmin worry what's installed.