Java 在 Jenkins 中运行编译的 Jar 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24644432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running a compiled Jar file in Jenkins
提问by user3246489
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.
我正在尝试通过 jenkins 运行一个可执行的 jar 文件。我在这里试图实现的是我创建了一个可执行的 jar 文件,并且它驻留在我的机器本地。我想把它放在 Git 中,然后在 jenkins 中运行它。有什么方法可以做到这一点吗?我对 Jenkins 完全陌生,如果有人可以提供帮助,它将为我节省很多时间。
采纳答案by gturri
You can do nearly everything you want with Jenkins since you can have it run arbitrary scripts / executables.
您可以使用 Jenkins 做几乎所有您想做的事情,因为您可以让它运行任意脚本/可执行文件。
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 ....
如果您想将此 .jar 放在 git 中,那么 Jenkins 作业将在获取 repo 时检索它。然后你只需要在构建中添加一个脚本 shell 步骤,并把你的命令行java my.jar my.class ....
On the other hand, it's sometimes frowned upto 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.
另一方面,将二进制文件放在 git 中有时会让人皱眉。如果 .jar 需要经常更新,则尤其如此。因此,您可能希望使用替代方法将 .jar 提供给 Jenkins 作业。例如使用 Maven 存储库。