Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant deploy simple Spring Boot web app to OpenShift

I have a .war file which when I copy to webapps folder in my local instance of Tomcat 9 then it deploys successfully. Somehow when I try to run it on Openshift gear(Tomcat 7) it doesnt get deployed. Steps I am taking:

0: I clone the remote repository.

1: I copy the war file to webapps folder in git repository.

2: I push it to remote repo and I get output:

Writing objects: 100% (5/5), 4.50 KiB | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
remote: Stopping jbossews cartridge
remote: Sending SIGTERM to jboss:341147 ...
remote: Building git ref 'master', commit 90c82a4
remote: Skipping Maven build due to absence of pom.xml
remote: Preparing build for deployment
remote: Deployment id is a9215a94
remote: Activating deployment
remote: Starting jbossews cartridge
remote: Found 127.12.55.129:8080 listening port
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
  • In the repo there was a .pom file and src folder which I deleted.

Project pom:

<?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.tomek.example</groupId>
    <artifactId>SimpleApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SimpleApp</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

<!--    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>-->


</project>

Main java:

@SpringBootApplication
@ComponentScan({"controllers", "rest"})
public class SimpleAppApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(SimpleAppApplication.class, args);

    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(applicationClass);
    }

    private static final Class<SimpleAppApplication> applicationClass = SimpleAppApplication.class;

}

Root Controller:

@RestController
public class MainController {


    @RequestMapping("/")
    public String text (){
        return "ja pierdole wygral jebany!";
    }

}

EDIT I checked server logs and I get lot of this type errors:

SEVERE: Unable to process Jar entry [javassist/ByteArrayClassPath.class] from Jar [jar:jndi:/localhost/Simple/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
        at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:796)
        at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
        at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
        at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1934)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1900)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1317)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

** Tomcat logs **

Oct 07, 2016 1:18:32 PM org.apache.catalina.startup.Catalina addClusterRuleSet
INFO: Cluster RuleSet not found due to [java.lang.ClassNotFoundException: org.apache.catalina.ha.ClusterRuleSet]. Cluster configuration disabled.
Oct 07, 2016 1:18:32 PM org.apache.catalina.startup.Catalina addClusterRuleSet
INFO: Cluster RuleSet not found due to [java.lang.ClassNotFoundException: org.apache.catalina.ha.ClusterRuleSet]. Cluster configuration disabled.
Oct 07, 2016 1:18:33 PM org.apache.catalina.core.AprLifecycleListener init
INFO: 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/i386:/lib:/usr/lib
Oct 07, 2016 1:18:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-127.9.153.1-8080"]
Oct 07, 2016 1:18:33 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1763 ms
Oct 07, 2016 1:18:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 07, 2016 1:18:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Oct 07, 2016 1:18:34 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/openshift/57efecb17628e18e59000032/app-root/runtime/dependencies/jbossews/webapps/ROOT.war
Oct 07, 2016 1:18:47 PM org.apache.catalina.startup.ContextConfig processAnnotationsJar
SEVERE: Unable to process Jar entry [javassist/ByteArrayClassPath.class] from Jar [jar:jndi:/localhost/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
        at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:796)
        at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
        at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
        at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1934)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1900)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1317)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

... lots of the same exception ...

Oct 07, 2016 1:18:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.9.153.1-8080"]
Oct 07, 2016 1:18:52 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 18101 ms
like image 626
Tomasz Mularczyk Avatar asked Oct 01 '16 14:10

Tomasz Mularczyk


1 Answers

For now see four problems:

  • Dependency org.javassist

mvn dependency:tree shows

[INFO] \- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.4.1.RELEASE:compile
[INFO]    +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO]    |  +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO]    |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO]    |  |  +- org.javassist:javassist:jar:3.20.0-GA:compile (version managed from 3.16.1-GA)
[INFO]    |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO]    |  \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO]    \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO]       \- org.codehaus.groovy:groovy:jar:2.4.7:compile (version managed from 2.4.3)

that dependency comes form spring-boot-starter-thymeleaf

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.17.1-GA</version>
</dependency>

due to OpenShift Tomcat Processing Annotations Error Deploying War

  • Tomcat version

Tomcat version could be changed though properties in pom.xml

    <properties>
        <java.version>1.7</java.version>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <start-class>com.example.SimpleAppApplication</start-class>
        <tomcat.version>7.0.54</tomcat.version>
    </properties>
  • OpenShift java version

Check if exist marker file .openshift/markers/java7 on OpenShift git repo due to https://developers.openshift.com/servers/tomcat/getting-started.html#other

optionally you can add marker .openshift/markers/skip_maven_build to skip maven build.

  • Loading controllers

If PagesController.java is on controllers package

    @Configuration
    @EnableAutoConfiguration
    @ComponentScan("controllers")
    @RestController
    public class SimpleAppApplication extends SpringBootServletInitializer {

        @Override
        protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
            return application;
        }

        public static void main(String[] args) {
            SpringApplication.run(SimpleAppApplication.class, args);
        }
    }
like image 159
adamski.pro Avatar answered Oct 01 '22 04:10

adamski.pro