Leo Hilbert Leo Hilbert - 2 months ago 15
Java Question

AWS Elastic Beanstalk: Tomcat ignoring my WAR-File

i'm trying to get my Spring Boot Application into AWS-EB and I already succeeded yesterday using Java as my Platform. However having Tomcat as Platform in EB allows me to configure platform-specific properties (database etc) directly in my AWS-Console so I created a new environment with Tomcat as the underlying platform.
Now I deployed my WAR-File (that worked yesterday with plain java) and the tomcat is completely ignoring me :(
See the log attached below. I don't see an error-message anywhere it just boots up but does not deploy the WAR-File anywhere. Does anyone have an idea what I'm missing? I haven't found anyone having the same problem.

Thanks in advance! :)

Catalina.out

23-Sep-2016 13:20:34.889 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.0.36
23-Sep-2016 13:20:34.892 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Aug 12 2016 18:14:42 UTC
23-Sep-2016 13:20:34.892 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.0.36.0
23-Sep-2016 13:20:34.892 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
23-Sep-2016 13:20:34.892 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.4.16-27.56.amzn1.x86_64
23-Sep-2016 13:20:34.892 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
23-Sep-2016 13:20:34.893 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.24.amzn1.x86_64/jre
23-Sep-2016 13:20:34.897 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_101-b13
23-Sep-2016 13:20:34.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
23-Sep-2016 13:20:34.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /usr/share/tomcat8
23-Sep-2016 13:20:34.901 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/share/tomcat8
23-Sep-2016 13:20:34.902 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dspring.datasource.username=USERNAME
23-Sep-2016 13:20:34.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -DPORT=8080
23-Sep-2016 13:20:34.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dspring.datasource.url=DATABASE_URL
23-Sep-2016 13:20:34.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -DJDBC_CONNECTION_STRING=
23-Sep-2016 13:20:34.903 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dspring.datasource.password=PASS
23-Sep-2016 13:20:34.904 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms256m
23-Sep-2016 13:20:34.904 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
23-Sep-2016 13:20:34.904 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:MaxPermSize=64m
23-Sep-2016 13:20:34.904 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/share/tomcat8
23-Sep-2016 13:20:34.904 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/share/tomcat8
23-Sep-2016 13:20:34.905 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.awt.headless=true
23-Sep-2016 13:20:34.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.endorsed.dirs=
23-Sep-2016 13:20:34.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/var/cache/tomcat8/temp
23-Sep-2016 13:20:34.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/share/tomcat8/conf/logging.properties
23-Sep-2016 13:20:34.906 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
23-Sep-2016 13:20:34.906 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
23-Sep-2016 13:20:35.119 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
23-Sep-2016 13:20:35.162 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
23-Sep-2016 13:20:35.174 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
23-Sep-2016 13:20:35.176 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
23-Sep-2016 13:20:35.181 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1218 ms
23-Sep-2016 13:20:35.237 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
23-Sep-2016 13:20:35.237 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.36
23-Sep-2016 13:20:35.261 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /var/lib/tomcat8/webapps/ROOT
23-Sep-2016 13:20:38.313 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
23-Sep-2016 13:20:38.362 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /var/lib/tomcat8/webapps/ROOT has finished in 3,101 ms
23-Sep-2016 13:20:38.368 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
23-Sep-2016 13:20:38.377 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
23-Sep-2016 13:20:38.377 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 3196 ms


Screenshot from my config:

enter image description here

Answer

I solved it by using the normal Java Platform in EB and parsing an environment-variable to a JVM arg, before I start my spring-server.

Here's the code for the Spring Boot-App

public class EnvironmentVariableParser {
    private static final Log log = LogFactory.getLog(EnvironmentVariableParser.class);

    public static void appendArguments() {
        final String customJvmArgs = System.getenv().get("CUSTOM_JVM_ARGS");
        if (customJvmArgs == null) {
            return;
        }

        for (String entry : customJvmArgs.split(" ")) {
            log.info(String.format("found custom jvm arg for: %s", entry));
            final int separator = entry.indexOf('=');
            System.setProperty(entry.substring(0, separator), entry.substring(separator + 1, entry.length()));
        }
    }
}

After that you can just call it, before you start your Application

public static void main(String[] args) {
        EnvironmentVariableParser.appendArguments();
        SpringApplication.run(MyServerApplication.class, args);
}

Then you can just specify "CUSTOM_JVM_ARGS" as an environment-variable and paste in your properties (seperated by spaces). Not the prettiest thing ever, but it works.. :P

Comments