Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Feb 7, 2017

Running your spring-boot app in Bitesize

First of all we have to have the spring-boot code in a git(svn) repo. I have create a sample spring-boot application using maven archetypes. You can find the code in;

Compile the code and generate the package using following command;
# cd SpringBoot
# mvn clean package
This will build the app and create a jar file called 'SpringBoot-1.0.0.jar'.

We can run the application with following command and it will start it in port 8080.
# java -jar target/SpringBoot-1.0.0.jar
Now we switch to the next part. In this we need to update the bitesize files according to our needs.

First we'll update the 'build.bitesize' file. In this we need to update the projects and name accordingly and give the source code repo url and related details as in all other projects. But if you look at the shell commands you can see that I have modified few of those. I have add the 'mvn clean package' command and change the 'cp' command to copy the build jar to '/app' directory. Then it will build the deb as previous.
project: spring-dev
  - name: spring-app
    os: linux
      branch: master
      - shell: sudo mkdir -p /app
      - shell: sudo mvn clean package
      - shell: sudo cp -rf target/*.jar /app
      - shell: sudo /usr/local/bin/fpm -s dir -n spring-app --iteration $(date "+%Y%m%d%H%M%S") -t deb /app
      - location: "*.deb"
Then we'll check the 'application.bitesize' file. I have change the 'runtime' to an ububtu-jdk8. Then change the command to run the jar.
project: spring-dev
  - name: spring-app
    runtime: ubuntu-jdk8:1.0
    version: "0.1.0"
      - name: spring-app 
        type: debian-package
          build: spring-app
        version: 1.0
    command: "java -jar /app/SpringBoot-1.0.0.jar"
In the 'environments.bitesize' I have update the port to 8080.
project: spring-dev
  - name: production
    namespace: spring-dev
      method: rolling-upgrade
      - name: spring-app
        port: 8080 
        ssl: "false"
        replicas: 2
In the stackstorm create_ns option give the correct manspace and the repo-url.
Reference :

May 7, 2014

Run WSO2 products in a Docker container

Docker is an open-source project to easily create lightweight, portable, self-sufficient containers from any application. There are two ways to run docker container;

1. Run a pre-build docker image.
2. Build your own docker image and use it.

In the first option you can use a base image like Ubuntu, CentOS or an image built by someone else like thilina/ubuntu_puppetmaster. You can find these images

In the second option you can build the image using a "Dockerfile". In this approach we can do customizations to the container by editing this file.

When creating a docker container for WSO2 products option 2 is the best. I have wrote a sample Dockerfile on github. It describes how to build a Docker container for WSO2 API manager single node implementation. For the moment docker have some limitations like unable to edit the '/etc/hosts' file, etc. If you need to create a clusters of WSO2 products (an API manager cluster in this case) you need to do some additional things like setting up a DNS server, etc.

How to build an API manager docker container?

Get a git clone of the build repository.
git clone
Download Oracle JDK 7 tar.gz (not JDK 8) and place it in '/dockerfiles/base/dist/'
mv /jdk-7u55-linux-x64.tar.gz /dockerfiles/base/dist/
Download WSO2 API manager and place that in '/dockerfiles/base/dist/'
mv / /dockerfiles/base/dist/
Change directory to '/dockerfiles/base/'.
cd dockerfiles/base/
Run docker command to build image.
docker build -t apim_image .

How to start API manager from the build image?

Start in interactive mode
docker run -i -t --name apim_test apim_image
Start in daemon mode
docker run -d    --name apim_test apim_image
Other options that can use when starting a docker image
--dns  < dns server address >
--host < hostname of the container >

Major disadvantages in docker (for the moment)

  • Can't edit the '/etc/hosts' file in the container.
  • Can't edit the '/etc/hostname' file. --host option can use to set a hostname when starting.
  • Can't change DNS server settings in '/etc/resolve.conf'. --dns option can use to set DNS servers. Therefore, if you need to create a WSO2 product cluster you need to setup a  DNS server too.

Read more about WSO2 API manager : Getting Started with API Manager

May 19, 2012

Create a maven distribution package including a jar with dependencies

In this post I will show how to create a distribution package (zip/tar.gz) using maven. Package will contain the executable jar and other relevant file such as README, License etc.

First I will create the jar including all the dependencies. To do that I add following code to my pom.xml

In this pom.xml, it reffers to another xml file call dist.xml. This xml file contains all the details about the distribution package we are going to generate.
<assembly xmlns=""

You should note following thing on pom.xml and dist.xml.

In pom.xml

  • Replace this " <mainclass<HelloWorld.App</mainclass> " with your main class.
  • Replace this " <descriptor>src/main/dist.xml</descriptor> " with your dist.xml file path.

In dist.xml

  • Use <files> to add files.
  • Use <fileSets> to add directories.
  • Use <outputDirectory> to specify the destination of each file/directory.

For more details : Maven assembly plugin examples