I use Eclipse and Gradle for a few "desktop" / command line Java application projects, including multi-project projects.
But I haven't used Gradle for a Java web application project in Eclipse so far. My usual approach is:
- Create empty workspace and configure it (JDK, Runtime environment Tomcat server)
- "Create a Dynamic Web project", run through wizard
And everything works fine. The project has a proper structure (WEB-INF exists, web.xml is created etc.), it compiles and it is deployed automatically to Tomcat by Eclipse. CATALINA_BASE is set to some temp folder in the workspace.
But how do I create a Gradle project which is a "Dynamic Web project" and not just a command line Java application or java-library?
I have tried two approaches:
Create a Gradle project using the wizard in Eclipse. It seems to create a
java-libraryproject always with alibsubproject. Having created the "wrapper" project and the actual Gradle projectlib, setjavaandwaras plugins for this. Open the project properties of the Gradle projectlib, Project Facets, add Dynamic Web Project Facet (4.0). Create run configuration to make it run in Tomcat server.Create a Gradle project using
gradle initin an empty directory. Createapplicationproject instead of library. Import that existing Gradle project into an empty workspace (instead of using Eclipse to create the project). And apply the same procedures as above (facet etc.).
None of the approaches gave me a working, ready-to-use web application project that has the expected folder structures (WebContent, WEB-INF, ...), that deploys correctly (no deployment or e.g. web.xml missing) ...
I spent several hours to use Gradle in a Java web application project in Eclipse. (Because I want to profit from its easy declarative dependency management.) But I didn't manage to make it work.
Also the samples in the Gradle docs do not contain a Java web application project: https://docs.gradle.org/current/samples/index.html Only Java Application or Java Library.
Has someone else already managed to set this up?
- Gradle 7.0.x
- Eclipse 2021-03
- Tomcat 9 or 10 (I've tried both)
- AdoptOpenJDK 11
- Windows machine
Please share your approach. :)