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 directory src/main/java/gradle/sample
, we need to create a new file SampleApp.java
. The following code listing shows the contents of the file. We 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; import java.util.ResourceBundle; public class SampleApp { public SampleApp() { } public static void main(final String[] arguments) { final SampleApp app = new SampleApp(); app.welcomeMessage(); } public void welcomeMessage() { final String welcomeMessage = readMessage(); showMessage(welcomeMessage); } private String readMessage() { final...