I have a UrbanCode Deploy process with a Command Line step that will run an executable jar myjar.jar
In Windows command line, to run as a separate process (so that the command line won't be blocked after I run the jar)
start java -jar myjar.jar
However if I run this command in a uDeploy step, the deploy process will just keep running (I assume it doesn't spawn a separate process).
How to achieve this via uDeploy? Thank you
Try using Deamon option https://developer.ibm.com/urbancode/plugindoc/ibmucd/shell/1-2/steps/, this will run in the background and will not hold your current step for long
Related
I have built an executable jar file which is also a standalone SpringBoot Application. The requirement is that I have to run this jar file from command line which also provides command line arguments which are meant to override application.properties properties and will be used further.
I have tried and this works perfectly when ran from Windows Command Prompt.
Now I further want to deploy this on jenkins and run the same jar file usign jenkins using the command:Note that the command is important since it overrides application.properties.
Will it work in jenkins? Should i go with "Execute Shell" or "Execute Windows batch command" for it in jenkins? I would be trying it but need o know .
Command: java -jar myJArName.jar --server.port=10 --another.argument=1 --another.argument=2
Yes, you can use execute shell as you mentioned above if:
Java is installed on the host that Jenkins runs on
java is part of $PATH (you can check this by running which java on your jenkins host)
myJarName.jar is actually on the host jenkins runs on
Btw. I assume Jenkins runs on a Linux host. Otherwise you might have to use Execute Windows batch command which will work in a similar way to execute shell, but I never used it.
I want to make job on Jenkins that starts server (MockServer on WireMock).
Server is launched from *.jar file, from terminal like that.
java -jar serverLaunch.jar
It takes over my console. To avoid that I modify this and do:
java -jar serverLaunch.jar &>/dev/null &
And that works for me on my local PC. Now I want to move it to Jenkins.
If I try to do this from "Shell command" block in Jenkins Job then:
a) java -jar serverLaunch.jar
I have task locked in queue in my Jenkins and I don't want that but server starts and works.
b) java -jar serverLaunch.jar &>/dev/null &
Job ends with success but my server is not alive.
I have wrapped this command also in .sh script and .rb script. Any idea how to make it work?
I've tried this:
https://wiki.jenkins-ci.org/display/JENKINS/Spawning+processes+from+build
And then in Jenkins "Shell script":
daemonize -E BUILD_ID=dontKillMe /bin/bash launch.sh
But it also passes but server is not alive.
I had to check "Inject environment variables to the build process" and add:
BUILD_ID=dontKillMe
Now it is working.
Try using nohup e.g.:
nohup java -jar serverLaunch.jar &
That should prevent the process being terminated when the parent shell process exits (which I suspect is your problem).
Another effective approach would be to add a post-build action that executes a shell spawning the server.
I need to open run two jar applications in the same time
I know that to run a jar file you have to type
java -jar app1.jar
but I need to terminate the current process to run
java -jar app2.jar
How can I open app2 without closing app1 ?
Execute this bash command
( java -jar app1.jar ) &
( java -jar app2.jar )
The commands will execute in parallel subshells
You can run one, push it into the background, and then run the other.
Run the first command, press ctrl-z and then type bg.
This runs the command in the background, leaving your command line available for you to call you next command.
http://www.thegeekstuff.com/2010/05/unix-background-job/
It is possible to execute external commands in java at run time.
However, what I am looking for is to actually open cmd or terminal and show that executing external command on screen.
I tried to execute a jar console application as java -jar jartool arguments, it works both on Windows and Ubuntu. The only problem is that, this does not open cmd or terminal separately. it runs the command in background.
We can use either ProcessBuilder and the start process or simply Runtime.getRuntime().exec.
I need to forcefully open the cmd or terminal. Java is configured to show console on windows but still no luck.
Any idea why this is happening or what should I do to force it to open cmd or terminal independent of current cmd or terminal.
I have compiled my JAVA code into a jar file which I have ported to my ubuntu server. I can start it manually the usual way using java -jar myJar.jar but I'd like my program to be active only for 8 hours. How can I go about setting my jar file up as a process which starts at 9AM and also which automatically closes at 5PM?
I would write a simple launcher script that does the following:
Takes two command line options:
--start
Set up the classpath and environment like JAVA_HOME for the jar to run.
Spawn java -jar myJar.jar.
Capture the process ID and store it in the myJar.pid file in a specific location.
--stop
Read the process ID from myJar.pid and send a kill signal.
Then schedule two jobs in cron, one to call this launcher script with --start argument, at 9AM, and the other to call the same script with --stop argument, at 5PM.
I would also have a shutdown hook registered in my application to gracefully exit when the kill signal is issued.