Search code examples
javaspring-boothttp-status-code-404embedded-tomcat-8

Unable to browse to spring boot application using embedded Tomcat


I am working on a rather large MVC project that used to run (perfectly) with just spring MVC, not spring boot. I have finished converting it to spring boot and it runs perfectly in Netbeans and when run as a standalone JAR outside of Netbeans on my development machine.

I transported the JAR file to its destination server and everything starts normally according to the console, I get this message: Tomcat started on the port(s): 8081 (HTTP) with context path '/MDHIS'. However, I am unable to browse to it as I would on my machine with the following URL: http://localhost:8081/MDHIS/.

I set tomcat to debug mode and it logs some interesting things :

[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.269] o.a.j.s.JspServlet                       
: JspEngine --> /WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.270] o.a.j.s.JspServlet                       
:        ServletPath: /WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.270] o.a.j.s.JspServlet                       
:           PathInfo: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.272] o.a.j.s.JspServlet                       
:           RealPath: C:\Users\Administrator\AppData\Local\Temp\tomcat- 
docbase.4901819852507265388.8080\WEB-INF\views\login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.273] o.a.j.s.JspServlet                       
:         RequestURI: /MDHIS/WEB-INF/views/login.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.274] o.a.j.s.JspServlet                       
:        QueryString: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.275] o.a.c.c.C.[.[.[.[jsp]                    
:  Disabling the response for further output
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.277] o.a.c.c.C.[.[localhost]                  
: Processing ErrorPage[errorCode=0, location=/error]
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.315] o.a.j.s.JspServlet                       
: JspEngine --> /WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.315] o.a.j.s.JspServlet                       
:        ServletPath: /WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.316] o.a.j.s.JspServlet                       
:           PathInfo: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.317] o.a.j.s.JspServlet                       
:           RealPath: C:\Users\Administrator\AppData\Local\Temp\tomcat- 
docbase.4901819852507265388.8080\WEB-INF\views\error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.318] o.a.j.s.JspServlet                       
:         RequestURI: /MDHIS/WEB-INF/views/error.jsp
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.319] o.a.j.s.JspServlet                       
:        QueryString: null
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.319] o.a.c.c.C.[.[.[.[jsp]                    
:  Disabling the response for further output
[WEBCLIENT] [DEBUG] [2018-10-15 14:44:26.320] o.a.c.c.C.[.[.[. 
[dispatcherServlet]      :  Disabling the response for further output

I watched the docbase folder and no JSPs or classes are ever added to it. I am having mixed results of this working or not on different environments / OSes / networks. Has any one ever seen this behavior?

******EDIT******

POM.xml files as requested :

Common project :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mdenis</groupId>
<artifactId>MDHIS_Common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<dependencies>

    <!--JAVA-->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
    </dependency>

    <!--SPRING-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
    <exclusion>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-logging</artifactId>
    </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>

    <!--MICROSOFT-->
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
    </dependency>

    <!--HIBERNATE-->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
    </dependency>

    <!--HAPI-->
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-base</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v26</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v25</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v24</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v231</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v23</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v22</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>ca.uhn.hapi</groupId>
        <artifactId>hapi-structures-v21</artifactId>
        <version>2.3</version>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>MDHIS_Common</finalName>
                <appendAssemblyId>false</appendAssemblyId>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

Web client :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mdenis</groupId>
<artifactId>MDHIS_WebClient</artifactId>
<version>1.0-SNAPSHOT</version>
<!--<packaging>war</packaging>-->

<name>MDHIS_WebClient</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
</parent>

<dependencies>

    <!--JAVA-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>8.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.json.bind</groupId>
        <artifactId>javax.json.bind-api</artifactId>
    </dependency> 
    <dependency>
        <groupId>javax.el</groupId>
        <artifactId>javax.el-api</artifactId>
        <version>3.0.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <!--GLASSFISH-->
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.el</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.1.3</version>
    </dependency>

    <!--TOMCAT-->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

    <!--JASPER REPORTS-->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.7.0</version>
    </dependency>

    <!--SIGAR-->
    <dependency>
        <groupId>org.fusesource</groupId>
        <artifactId>sigar</artifactId>
        <version>1.6.4</version>
    </dependency>

    <!--LOG4J2-->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-1.2-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jul</artifactId>
    </dependency>

    <!--YASSON-->
    <dependency>
        <groupId>org.eclipse</groupId>
        <artifactId>yasson</artifactId>
        <version>1.1.0-SNAPSHOT</version>
    </dependency>

    <!--MDHIS_COMMON-->
    <dependency>
        <groupId>com.mdenis</groupId>
        <artifactId>MDHIS_Common</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

</dependencies>

<repositories>

    <repository>
        <id>java.net-Public</id>
        <name>Maven Java Net Snapshots and Releases</name>
        <url>https://maven.java.net/content/groups/public/</url>
    </repository>
    <repository>
        <id>yasson-snapshots</id>
        <name>Yasson Snapshots repository</name>
        <url>https://repo.eclipse.org/content/repositories/yasson-snapshots</url>
    </repository>

</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

CONCLUSION

Thanks to everyone that helped! Although it was working fine on some systems when packaged as a JAR file, the change to a WAR file is what fixed it. I can sadly no longer run the project in Netbeans because it fails to recognize that a Tomcat server is embedded within itself but everything works perfectly when using java -jar on 2 systems (Windows Server 2016 and Ubuntu LTS 18.04) that were previously not working.

Thanks


Solution

  • Faced with such kind of problem, I would probe what could be environmental differences between local machine (where the app is running fine) and server (where the same app is giving problem). First few things I would check are as follows:

    1. Check if the JSP's are getting compiled to the work directory of Tomcat.
    2. Check JAVA_HOME variable picked up by Tomcat.
    3. Check if the JDK (and not just JRE) is indeed installed on the machine.
    4. Check if the Java version configured for Tomcat is supported by Spring Boot version used.
    5. Check the dependencies in the effective pom that have the scope "provided", "runtime" or "system".

    But first and foremost, please refer these JSP Limitations with Spring Boot and note that you need to use a war packaging -- JSPs are not supported when using an executable jar. This executable war will work when launched with java -jar, and will also be deployable to any standard container.

    To create a war packaging, include <packaging>war</packaging> in the pom where the artifact ID is declared.

    You may find this Spring Boot JSP sample useful. This another sample may also be helpful.

    Hope the above inputs lead to a solution.