Create a web application using gradle

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

The article will deal with creating a web application with gradle build tool. Previously we have seen how to create a java project and eclipse project using gradle. Now we want to create a web application using gradle.

Web Application using Gradle

If you want to create a web application using gradle, you need to have the application in following format.

  • src/main/java : This folder has java sources.
  • src/main/resources: This folder can hold property files and other resources
  • src/main/webapp: This folder holds jsp and other web application content.

Let us create a java class HelloWorld.java which has a method which simply returns a text greeting. The java file is located at src/main/java/com/thejavageek/gradle/HelloWorld.java

We are not putting anything as resources here.

Create a file index.jsp in src/main/webapp/ directory with following content

Now we can create a war file directly from sources above and also create an eclipse web project. We just need to use war and eclipse-wtp plugins in build.gradle. Build.gradle is as below

war plugin bundles the web application into a war file and eclipse-wtp tells that build should create eclipse web project which can be useful for being imported in eclipse

Now we are ready to create web application using Gradle build file.

Open command prompt and navigate to root directory of your project and run gradle build. It should build as below.

gradle web app buildThis will create web application using gradle bulid command. After it is done, you can see war file is generated in build/libs directory. You can directly deploy the war into your favourite server and visit the index page by hitting url

http://localhost:8080/webproject/index.jsp

 

It should print hello message. If you want to import the web project in eclipse, you can run gradle eclipse command.

 

I hope this article helped create web application using gradle. In subsequent articles we are going to see more about them.

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

4 thoughts on “Create a web application using gradle

Leave a Reply

Your email address will not be published. Required fields are marked *