Anil Bhaskar
Anil Bhaskar

Reputation: 3978

Openshift - Spring Boot - Error creating new application - Failed to execute: 'control start'

I am trying to deploy a very simple Spring-Boot application on Openshift. I am creating Tomcat 7 (JBoss EWS 2.0) Cartridge using openshift online from browser.

I am getting following errors while creating it. enter image description here

and

enter image description here Could not find any solution for that. Could someone help that what is going wrong here.

Git URL: https://github.com/bhaskey/testingcloud

Upvotes: 1

Views: 498

Answers (1)

Karthik Prasad
Karthik Prasad

Reputation: 10004

Not sure what is the exact reason for error. However I find following issues in you code.

  • Java Version Not sure if JBoss EWS 2.0 supports 1.7(In generated pom.xml deafults to 1.7)
  • You are deploying on Tomcat server, however spring-boot-starter-web has transitive dependency on spring-boot-starter-tomcat. You need to set tomcat dependency to provided.
  • Your packing is jar and you've spring boot maven plugin not sure, how it is going to be deploy to tomcat server's webapps directory. it uses openshift profile to build the project. and your openshift profile might not work as expected.
  • In order for spring boot to run on external app server, you need to extend your main class with extends SpringBootServletInitializer

However I would suggest you to follow these steps to create spring boot project deployable to openshift.

  1. Create Tomcat 7 (JBoss EWS 2.0) Cartridge from web console or Eclipse openshift plugin.
  2. Clone the project to your local machine.
  3. Modify pom.xml, add spring boot parent dependency and add only dependencies. Leave plugin as it is. The updated pom.xml would look something like this.

    <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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.openshif</groupId>
    <artifactId>cloudemo</artifactId>
    <packaging>war</packaging>
    <version>1.0</version>
    <name>cloudemo</name>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <repositories>
        <repository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>eap</id>
            <url>http://maven.repository.redhat.com/techpreview/all</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
        <java.version>1.6</java.version>
    </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-web</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <!-- When built in OpenShift the 'openshift' profile will be used when 
                invoking mvn. -->
            <!-- Use this profile for any OpenShift specific customization your app 
                will need. -->
            <!-- By default that is to put the resulting archive into the 'webapps' 
                folder. -->
            <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
            <id>openshift</id>
            <build>
                <finalName>cloudemo</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.1.1</version>
                        <configuration>
                            <outputDirectory>webapps</outputDirectory>
                            <warName>ROOT</warName>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    

  4. Modify MainClass file

    @SpringBootApplication
    public class CloudemoApplication extends SpringBootServletInitializer  {
    
    
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    
        return builder.sources(CloudemoApplication.class);
    }
    
    public static void main(String[] args) {
        SpringApplication.run(CloudemoApplication.class, args);
    }
    
  5. Since your application doesn't use spring boot plugin you might need to place all your html, css, js resources under webapps directory

Upvotes: 1

Related Questions