Gradle dynamic web application template - Eclipse

eclipse

(Cristian) #1

I am complete new to gradle and have so far made a working gradle installation on my machine and installed the Eclipse gradle plugin (buildship).

Now i would like to create a gradle project with the structure file of Eclipse’s Dynamic Web Project
that also adds

  • deployment descriptor
  • Dynamic web module version
  • Tomcat library
  • With more

Please see image for file and folder structure example of new project
eclipse-dynamic-web

How can i do this?

What i was initially trying to accomplish when i was suggested to use gradle was to have an easy way to add dependencies such as oAuth to a web project.

I tried to see the https://guides.gradle.org/building-java-web-applications/ guide, but this removes the entire structure that i am used to and i also had other issues i could not figure out how to get past so i ended up with a non working project that could not display the index.html page and instead showed a “Directory: project/path” H1 element from Jetty?
Thanks in advance


(Cristian) #2

For others that stumple upon this.
I have learned that it’s not possible to have the Eclipse Dynamic Web Project file and folder structure.
So i created the structure as follows

  • src
    • main
      • java
      • resources
      • webapp
        • META-INF
        • WEB-INF
          • web.xml
          • lib

With the following build.gradle file
apply plugin: 'java’
apply plugin: 'war’
apply plugin: 'eclipse-wtp’
apply plugin: ‘com.bmuschko.tomcat’

repositories {
jcenter()
}

dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.1.0’
testCompile ‘junit:junit:4.12’
}

/*
TOMCAT BUILD CONFIGURATION
*/
repositories {
mavenCentral()
}

dependencies {
def tomcatVersion = '8.5.29’
tomcat “org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}”,
“org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}”
}

tomcat {
httpProtocol = 'org.apache.coyote.http11.Http11Nio2Protocol’
ajpProtocol = ‘org.apache.coyote.ajp.AjpNio2Protocol’
}

/*
TOMCAT BUILD SCRIPT BUILD CONFIGURATION - EXTERNAL DEPENDENCIES
*/
buildscript {
repositories {
jcenter()
}

dependencies {
	classpath 'com.bmuschko:gradle-tomcat-plugin:2.4.2'
}

}

I have also found out that you need to add https://mvnrepository.com/artifact/javax.servlet.jsp/jsp-api/2.2.1-b03 to be able to handle JSP exceptions