1

I am new to tomcat. I run "gradle tomcatRunWar". This web application can run locally and WebApplicationInitializer was called. Then, I used "gradle war" to get war file. I deleted everything in /var/lib/tomcat7/webapps/. I copied myproject.war to /var/lib/tomcat7/webapps/ directory. Renamed it as ROOT.war. Re-started tomcat7. The server started to run. But I can not access my webpage on my_ip:8080/login OR my_ip:8080/myproject/login. The error is "HTTP Status 404 - /login". In the localhost.log, there is an info: “INFO: No Spring WebApplicationInitializer types detected on classpath”. I searched this problem by Google, some people had the same problems because of the lib version, jdk version. I have no idea how to debug.

Apache Tomcat/7.0.52, java version "1.8.0_45" Java(TM) SE Runtime Environment (build 1.8.0_45-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

build.gradle is:

    buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-release" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.1.RELEASE")
        classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:1.2.4'
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'war'
apply plugin: 'groovy'
apply plugin: 'tomcat'


eclipse {
    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.7
    }
}

jar {
    baseName = 'myproject'
    version =  '0.1.0'
}

repositories {
    mavenCentral()
    maven { url "http://repo.spring.io/libs-release" }
}


dependencies {
    compile('commons-fileupload:commons-fileupload:1.3.1')
    compile("org.codehaus.jackson:jackson-mapper-asl:1.9.0")
    compile("org.springframework.boot:spring-boot-starter-web") {
        exclude group: 'ch.qos.logback', module: 'logback-classic'
        exclude group: 'org.slf4j'
    }
    compile("javax.servlet:javax.servlet-api:3.0.1")
    providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    compile("org.springframework.data:spring-data-mongodb")  {
        exclude group: 'org.slf4j'
    }
    compile("org.springframework.security:spring-security-crypto:3.2.3.RELEASE")
    compile("com.fasterxml.jackson.core:jackson-databind")
    compile("joda-time:joda-time:2.2")
    compile("org.apache.directory.studio:org.apache.commons.codec:1.6")
    compile('com.amazonaws:aws-java-sdk:1.2.1')
    testCompile("junit:junit")
        runtime 'javax.servlet:jstl:1.2'
    providedCompile group:"org.apache.tomcat", name:"tomcat-catalina", version:"7.0.52" 
}

dependencies { 
    def tomcatVersion = '7.0.52' 
    tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", 
    "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}" 
    tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { 
        exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj' 
    } 
}

tomcatRun { 
    daemon = true 
    httpPort = 8080 
    outputFile = file('/logs/tomcat.log') 
    stopKey = 'ctl-d'  
}

tomcatRunWar { 
    outputFile = file('/logs/tomcat.log') 
}

tomcatStop { 
    stopKey = 'ctl-d' 
}

The /var/lib/tomcat7/logs/catalina.out is:

Aug 03, 2015 12:41:30 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Aug 03, 2015 12:41:30 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1009 ms
Aug 03, 2015 12:41:30 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Aug 03, 2015 12:41:30 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 (Ubuntu)
Aug 03, 2015 12:41:30 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/examples.xml
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core_rt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/core is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/core is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt_rt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/fmt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/fmt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/functions is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/permittedTaglibs is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://jakarta.apache.org/taglibs/standard/scriptfree is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql_rt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/sql is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/sql is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml_rt is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jstl/xml is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.TaglibUriRule body
INFO: TLD skipped. URI: http://java.sun.com/jsp/jstl/xml is already defined
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/docs.xml
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/manager.xml
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /etc/tomcat7/Catalina/localhost/host-manager.xml
Aug 03, 2015 12:41:31 AM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/tomcat7/webapps/ROOT.war

Aug 03, 2015 12:41:37 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 03, 2015 12:41:37 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 7788 ms

In the localhost.log, there is an info: “INFO: No Spring WebApplicationInitializer types detected on classpath

My Application.java is:

    @Configuration
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {
      @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application.sources(Application.class);
        }

        public static void main(String[] args) throws Exception {
            SpringApplication.run(Application.class, args);
        }

}

My WebAppInitializer.java is:

@Configuration
public class WebAppInitializer implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext)
            throws ServletException {

        AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
        appContext.register(Application.class);
        ServletRegistration.Dynamic dispatcher = servletContext.addServlet(
                "SpringDispatcher", new DispatcherServlet(appContext));
        dispatcher.setLoadOnStartup(1);
        dispatcher.addMapping("/");
    }
}

UPDATE

I used web.xml instead of WebApplicationInitializer. Now it works.

BAE
  • 8,550
  • 22
  • 88
  • 171
  • 1
    Show the entire tomcat log. As text, not as picture. – Roman Aug 02 '15 at 22:09
  • 1
    I'm encountering the same problem (I happen to be using Eclipse/Spring/Maven, instead of Gradle). The problem - and several possible workarounds (besides just punting and using web.xml) are discussed here: http://stackoverflow.com/questions/22938689/ – paulsm4 Feb 10 '16 at 05:27

1 Answers1

1

The problem is about your access directory, you need to verify what is your CATALINA_HOME environment variable, the log is clear "directory don't exists".

Can't to access from the execution location.

SOLUTION: 1. First, try to start tomcat alone without using Gradle. 2. Deploy any hello world web application in your tomcat 3. Try to use Gradle Step by step 4. To learn more about Gradle look at here: http://examples.javacodegeeks.com/core-java/gradle/gradle-hello-world-tutorial/

Regards.