How to compile and run a simple java file in jenki

2019-01-14 14:03发布

I have installed Jenkins on Windows and created a job in Jenkins. I want to compile and execute a simple java file (say Hello.java). How can I do that?

My Hello.java contains the following code:

public class Hello {
    public static void main(String args[]){
        System.out.println("I'm dancing");
    }
}

2条回答
走好不送
2楼-- · 2019-01-14 14:46

Have a look at Maven for automatic builds on a continuous integration server such as Jenkins: http://www.sonatype.com/books/mvnref-book/reference/public-book.html

There is even an exec Plugin which allows you to execute a Java program using Maven, but this is rarely needed on a continuous integration server.

查看更多
小情绪 Triste *
3楼-- · 2019-01-14 14:51
  1. Go to configuration page of your job/project
  2. Select "Execute Windows batch command" from "Add build step" combo
  3. Type the following on Command field: javac Hello.java java Hello
  4. Save configuration
  5. Keep Hello.java on the folder /Jenkins/workspace/
  6. Build the project/job by clicking "Build Now" link and see the Console Output
查看更多
登录 后发表回答