Deploying tomcat web app with gradle

Answered

I want to deploy a webapp in Idea Ultimate with Gradle. Currently I can launch the tomcat 8.5.4 server but get a 404 when I try to browse to my context.

My build.gradle looks like:

 

group 'test'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'war'

sourceCompatibility = 1.7

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.5'
}


In Idea I can build:war ok In Idea I can launch tomcat and get a 404 If I login to tomcat/manager (when tomcat has been launched from Idea) I do not see my app listed.

If I launch tomcat from the CLI I can see my app listed but when I click on it I get 404

There are no errors in the log windows for starting the server in Idea or building the war.

I believe my issue is to do with the way Idea launches tomcat and deploy's the war - but I am not sure what exactly.

Idea launches my browser to localhost:8080 and in the browser I get $END$

 

 

 
0
3 comments

Please share the complete project to reproduce. The issue may be with your application layout.

0
Avatar
Permanently deleted user

yes good point. I would expect the full path to access the webpage index1.jsp to be localhost:8080/poltest/form

request.getRequestDispatcher("/index1.jsp").forward(request , response);

poltest being the name of the war and form being a url pattern

@WebServlet(name = "pol1310", urlPatterns = {"/form"})

I have shared the project zip which is only a few lines of code

https://drive.google.com/file/d/0B3rjaapNHpJJUWIwdnhXVlVlRDg/view?usp=sharing

0

Your servlet is not located in the source root, therefore it's not compiled and deployed on the server.

URL would also depend on the context you specify in IDE settings, there will be no /poltest in the URL if you deploy under the ROOT (/) context.

See https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout

0

Please sign in to leave a comment.