Question

I am trying to deploy the simplest application on Cloudbees, using the Spark Java framework. This produces a Jar file that I tried to deploy through the Jenkins push->deploy, but it warns me that the deploy plugin cannot deploy a jar file...

Whatever, I deployed my jar through the CloudBees SDK and the CLI :

bees app:deploy -t java -R java_version=1.7 target\myapp-with-dependencies.jar

And then it tells me that the application has been deployed to my URL. But when I try to reach this URL, I get a 502 Bad Gateway Error...

However, whether if run my main class through IntelliJ or with the Jar file produced by maven, the URL 127.0.0.1:8080 returns me the expected Hello Spark.

Here is my main class :

public class HelloSpark {
    public static void main(String[] args) {
        String port = System.getProperty("app.port","8080"); 
        //So that the port is the one used by CloudBees
        Spark.setPort(Integer.parseInt(port));
        Spark.get(new Route("/") {

            @Override
            public Object handle(Request request, Response response) {
                return "Hello Spark";
            }
        });
    }
}

And here is my pom file :

<?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>spark-from-scratch</groupId>
    <artifactId>spark-from-scratch</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>spark</groupId>
            <artifactId>spark</artifactId>
            <version>0.9.9.4-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>HelloSpark</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
Was it helpful?

Solution

I think you need to specify your main class in this way:

bees app:deploy -t java -R class=your.main.Class -R java_version=1.7 PATH_TO_APP_PACKAGE

OTHER TIPS

I think it's necessary to specify it in your command, you can read more here:

https://developer.cloudbees.com/bin/view/RUN/Java+Container

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top