3

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

4
  • I want to host it on the web, actually as a chron job on app-engine Commented Sep 30, 2016 at 15:49
  • So use something a lot higher-level, such as Spring MVC, so you aren't spending all your time fiddling with the infrastructure instead of the logic. Commented Sep 30, 2016 at 15:53
  • Regardless of whatever you're using (Spring MVC, Servlets etc.). Check out: stackoverflow.com/questions/26745541/… to add gradle support to your IntelliJ project. Commented Sep 30, 2016 at 16:01
  • I would suggest one bite at a time to eat an elephant.1.create servlet (no matter where) 2.Run it in IDEA 3.Add grade support 4.Whatever you want... Commented Sep 30, 2016 at 19:13

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.