Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a compiled Jar file in Jenkins

I am trying to run an executable jar file through jenkins. What I am trying to achieve here is I have an executable jar file created and is residing locally in my machine. I want to put it in Git and then run it in jenkins. Is there some how I can do this? I am totally new to Jenkins and if someone can help it will save me a lot of time.

like image 301
user3246489 Avatar asked Jul 09 '14 02:07

user3246489


People also ask

Can we deploy jar in Jenkins?

You just saw how to deploy a JAR file in Jenkins to do continuous deployment of a Java application that communicates with Couchbase Server. This Jenkins configuration will pull from GitHub, build a JAR, and deploy it. While it should be a little more polished in a production scenario, it is a good way to get started.

How do I run a JAR file from maven in Jenkins?

1 Answer. Show activity on this post. First of all, create a Jenkins Freestyle Project . Add the above code to Execute shell block in Build -> Add build step -> Execute shell in the job configuration.

How do I compile and run a JAR file?

To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar. We'll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …]


1 Answers

You can do nearly everything you want with Jenkins since you can have it run arbitrary scripts / executables.

If you want to put this .jar in git, then the Jenkins jobs will retrieve it when it fetches the repo. Then you just need to add a script shell step to the build, and to put your command line java my.jar my.class ....

On the other hand, it's sometimes frowned up to put binary files in git. It's true in particular if the .jar will need to be often updated. Hence you might want to provide the .jar to the Jenkins job using alternative methods. For example using a maven repository.

like image 70
gturri Avatar answered Oct 12 '22 06:10

gturri