Reputation: 15442
I want to create a simple java servlet in intellij IDEA.
I saw this page about how to do so,
But how can I make this web-project also a gradle project?
I want to evolve my servlet and add dependencies
I want to runt he servlet later and be able to debug it with breakpoints
Upvotes: 3
Views: 6937
Reputation: 349
First use IntelliJ to create a new Gradle Project. Second create a standard project structure for a webapp like:
src/main/java/yourPackage/yourServlet.java
src/main/webapp/WEB-INF/web.xml
src/main/webapp/index.html
Add the following to your gradle.build file:
apply plugin: 'jetty'
//also applies plugin: 'war'
//and this also applies plugin: 'java'
repositories{
mavenCentral()
}
dependencies {
compile 'javax.servlet:javax.servlet-api:3.1.0'
}
Now you can just build your project with the gradle (or gradlew if you use the wrapper) build task and run it with the jettyRun task. If you don't want to use jetty, you can use the war plugin without the jetty plugin and deploy your generated war file on every server you want. The war file will be located in projectRoot/build/libs
See also the user guide of gradle: Chapter 47. Web Application Quickstart
Upvotes: 7