IBM BlueMix is the new IBM cloud platform. It supports Docker, cloud foundry and openstack. As a default EE container, they offer WebSphere Liberty Profile. But your preferred EE server is not that complicated thanks to the extensibility of the platform.
This post shows how to deploy your TomEE application on BlueMix pretty quickly.
Create an account
First of all, create a BlueMic account if you already don’t have one, and log in. You should see something like . You can create a new “space” if you want but by default you should have the “dev” space. Spaces are mainly containers for “applications” (from VM to API).
Set up cloud foundry client
If you haven’t got it yet, install cloud foundry client (cf). You can download it here. Then set it up to be linked to your BlueMix account, type cf login
and fill the asked inputs:
$ cf login API endpoint> api.ng.bluemix.net Email> themail@theprovider.com Password> Authenticating ... OK Target org themail@theprovider.com Target space dev API endpoint: https://api.ng.bluemix.net (Version API: 2.23.0) User: themail@theprovider.com Org: themail@theprovider.com Space: dev
Prepare the application
We will use cloud foundry java buildback (kind of environment configuration). This means that we have to be able to run a main(String[])
which will deploy the web application on port provided in $PORT
environment variable. For that, we will use TomEE Embedded and a modified version of the shade explained on Tomitribe blog: 50 shades of TomEE. Our main (“Run” class) will be trivial and will simply setup the HTTP port as shown below:
public class Run { public static void main(final String[] args) throws Exception { final Configuration configuration = new Configuration().http(Integer.parseInt(System.getenv("PORT"))); try (final Container c = new Container(configuration).deployClasspathAsWebApp()) { new CountDownLatch(1).await(); } catch (final InterruptedException e) { Thread.interrupted(); } } }
Side note: to get a ready-to-deploy application, you can reuse tomee JAX-RS starter. For my part, I renamed the artifactId to “simple-jaxrs”. Here is what a pom for such a project can look like:
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <!-- Change: groupId, artifactId, version --> <groupId>org.superbiz</groupId> <artifactId>simple-jaxrs</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.apache.openejb</groupId> <artifactId>javaee-api</artifactId> <version>${openejb.javaee.api}</version> </dependency> <dependency> <groupId>org.apache.tomee</groupId> <artifactId>tomee-embedded</artifactId> <version>${tomee.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>org.superbiz.Run</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> <resource>META-INF/cxf/bus-extensions.txt</resource> </transformer> </transformers> <filters> <filter> <!-- we don't want JSF to be activated --> <artifact>*:*</artifact> <excludes> <exclude>META-INF/faces-config.xml</exclude> </excludes> </filter> </filters> </configuration> </execution> </executions> </plugin> </plugins> </build> <properties> <tomee.version>7.0.0-SNAPSHOT</tomee.version> <openejb.javaee.api>7.0-SNAPSHOT</openejb.javaee.api> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <failOnMissingWebXml>false</failOnMissingWebXml> <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> </properties> </project>
Deploy!
Deploying the application (or updating it) is done through a simple command:
cf push simplejaxrs -p target/simple-jaxrs-1.0-SNAPSHOT.jar -b java-buildpack
Here, it is important to specify the deployed executable jar (-p) and the buildpack to use (-b). This push command will deploy the applicaion. The logs are like:
Création de l'application simplejaxrs de l'org themail@theprovider.com / espace dev en tant que themail@theprovider.com... OK Création de la route simplejaxrs.mybluemix.net... OK Liaison de simplejaxrs.mybluemix.net à simplejaxrs... OK L'ajout simplejaxrs ... Téléchargement de fichiers d'applications à partir de: target/simple-jaxrs-1.0-SNAPSHOT.jar Téléchargement de 86.7M, 25080 fichiers Done uploading OK Arrêt de l'application simplejaxrs dans l'org themail@theprovider.com / espace dev en tant que themail@theprovider.com... OK À partir de l'application simplejaxrs dans l'org themail@theprovider.com / espace dev en tant que themail@theprovider.com... -----> Downloaded app package (40M) -----> Downloaded app buildpack cache (44M) Cloning into '/tmp/buildpacks/java-buildpack'... -----> Java Buildpack Version: b87847f | https://github.com/cloudfoundry/java-buildpack.git#b87847f -----> Downloading Open Jdk JRE 1.8.0_45 from https://download.run.pivotal.io/openjdk/lucid/x86_64/openjdk-1.8.0_45.tar.gz (found in cache) Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.4s) -----> Downloading Open JDK Like Memory Calculator 1.1.1_RELEASE from https://download.run.pivotal.io/memory-calculator/lucid/x86_64/memory-calculator-1.1.1_RELEASE (found in cache) Memory Settings: -XX:MaxMetaspaceSize=104857K -XX:MetaspaceSize=104857K -Xss1M -Xmx768M -Xms768M -----> Uploading droplet (71M) 0 de 1 d'instances en cours, 1 démarrage 0 de 1 d'instances en cours, 1 démarrage 0 de 1 d'instances en cours, 1 démarrage 1 de 1 d'instances en cours Application démarrée OK Application simplejaxrs a été démarrée avec la commande `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-1.1.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,stack:5,native:10 -totMemory=$MEMORY_LIMIT) && $PWD/.java-buildpack/open_jdk_jre/bin/java -cp $PWD/. -Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY org.superbiz.Run` Santé et état de l'application simplejaxrs de l'org themail@theprovider.com / espace dev en tant que themail@theprovider.com... OK État: started instances: 1/1 utilisation: 1G x 1 instances URLs: simplejaxrs.mybluemix.net dernier téléchargement: Wed Jun 17 17:07:56 UTC 2015 stack: lucid64 state depuis cpu mémoire disque details #0 fonctionne 2015-06-17 07:10:04 PM 58.7% 336.3M de 1G 270.9M sur 1G
Note: for an update, the three first blocks are replaced by:
Mise à jour de l'application simplejaxrs dans l'org themail@theprovider.com / espace dev comme themail@theprovider.com... OK
Then you can simply access the application on the provided url:
URLs: simplejaxrs.mybluemix.net
If you deployed the tomee JAX-RS starter application, have a look at http://simplejaxrs.mybluemix.net/color/object for instance. And here it is! For next application updates, build the project locally and re-execute push command. Also note that you can use cloudfoundry maven plugin to automate it and integrate it with your build/deployment infrastructure. If you go back to the BlueMix GUI you’ll see your application with few statistics, access to logs, environment…
could you record video then put youtube all actions please?
I don’t have much time but it is really just a matter of creating an account and running the 2 commands I shared. If you are stucked somewhere don’t hesitate to post the issue you encounter.
Romain,
The correct way to do this is to create a TomEE buildpack that is an upstream fork of the Java Buildpack https://github.com/cloudfoundry/java-buildpack. The java-buildpack stages apps within the Tomcat container. It would be trivial to make a TomEE buildpack – basically replacing the tomcat binary with TomEE and changing the release command of the buildpack. If you want to discuss more you can find me at @rkela or kelapure@gmail.com.
Creating a buildpack will allow customer apps to run in the cloud(Cloud Foundry and Bluemix) without any modifications. Each app will NOT have to include the TomEE runtime within the app.
-Thanks,
Rohit
cloud.rohitkelapure.com
There are TomEE buildpack already all around the net but then you depend on the creator and it is not the same deployment/dev lifecycle.
I think both make sense but wanted to show you dont have to follow the whole old EE lifecycle to develop an app in the cloud today.
Thanks for the comment BTW, really forgot to mention this option.
I am suggesting that the Apache TomEE team own the official TomEE buildpack and work with Cloud Foundry community to get it included first in the https://github.com/cloudfoundry-incubator and then graduate to https://github.com/cloudfoundry GitHub org. If you guys want to drive then I will be more than happy to start the community process. I could easily create the TomEE buildpack myself but then it will YET ANOTHER buildpack as you said 🙂
Do you care posting it on tomee dev list? This discussion should be done on our list but super happy if we can make it!
Would be glad to post on the TomEE mailing list. Thanks for being receptive!
Reblogged this on Dinesh Ram Kali..