Running Java applications
If we want to execute a Java executable from a Gradle build, we have several options. Before we explore these options, we will first create a new Java class with a main()
method in our project. We will execute this Java class from our build file.
In the src/main/java/gradle/sample
directory, we need to create a new SampleApp.java
file. The following code listing shows the contents of the file. We will use our Sample
class to print the value of the getWelcomeMessage()
method to System.out
:
// File: src/main/java/gradle/sample/SampleApp.java package gradle.sample; public class SampleApp { public SampleApp() { } public static void main(String[] args) { final SampleApp app = new SampleApp(); app.welcomeMessage(); } public void welcomeMessage() { final String welcomeMessage = readMessage(); showMessage(welcomeMessage); } private String readMessage() { final Sample sample = new Sample...