6

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
Tomasz Mularczyk
  • 34,501
  • 19
  • 112
  • 166

3 Answers3

4

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);
        }
    }
Community
  • 1
  • 1
  • I think specyfing tomcat version did its thing, because app is running! I can see the output of a root page, however rest of thymeleaf mappings cant be resolved `Could not initialize class org.thymeleaf.context.WebVariablesMap` – Tomasz Mularczyk Oct 13 '16 at 06:09
  • I edited answer and now should works properly. I managed to run it on my instance of OpenShift Tomcat. – adamski.pro Oct 19 '16 at 05:40
  • I skipped few steps. I just modified POM as you described and it worked. I'm so sorry that all the points and upvotes went for answers that didn't provide any help :( – Tomasz Mularczyk Oct 19 '16 at 18:48
3

Have you tried specifying war deployment on your pom.xml ?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
        <outputDirectory>target</outputDirectory>
        <warName>ROOT</warName>
    </configuration>
</plugin>
João Gonçalves
  • 3,903
  • 2
  • 22
  • 36
3

I think you have simply compiled in your local environment in Java 8 as by your pom and then pushed the war on openshift without pom and source so without rebuild. I would have expected a different exception, but this is my guess. Tomcat 7 on openshift run by default with Java 6 or Java 7 if you configure the marker. I suggest you to align your local configuration to the one present on openshift (jdk and tomcat) if you don't need the new feature of the latest version. You have also to change these lines in your pom.xml with the proper version of Java.

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

UPDATE 1

Please try also one of those solutions together with the above one:

     <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.1.0.Final</version>
        <exclusions>
            <exclusion>
                <groupId>org.javassist</groupId>
                <artifactId>javassist</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

or edit the file catalina.properties on the gear add: tomcat.util.scan.DefaultJarScanner.jarsToSkip=javassist-*.jar

UPDATE 2

I see you have a dependency to javaassist also due thymeleaf, then add also this exclusion to your pom and switch to java 1.7 because you have a web module 3.1 ( add a marker on openshift to make him use java 7)

<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>
</properties>

you cant exclude javaassist for thymeleaf so the only option. is to add:

 tomcat.util.scan.DefaultJarScanner.jarsToSkip = [existing exclusions] javassist-*.jar

to catalina.properties in openshift

Massimo
  • 1,012
  • 14
  • 23
  • You are right, open shift gear is running Java 7 which I didn't know. However changin project version to Java 7 or even 6 doesnt help and the same exception occurs. – Tomasz Mularczyk Oct 09 '16 at 07:53
  • doesnt help. If you would like heres the whole sample project https://bitbucket.org/Tomekmularczyk/todelete/src/637de418d9a77456ed9a1b1ef08c94769c4febf7?at=master – Tomasz Mularczyk Oct 10 '16 at 17:27