Using http proxies in openshift java projects

To use http proxies with java in openshift you should know:

– that tools like maven don’t honor http_proxy & co environment variables
– that each container image has its own build script (assemble) that does or does NOT take http_proxy into account.

Always check the image documentation if you need proxies:


A general and flexible solution is:

– to provide a configuration/settings.xml in your project, eg.
- pom.xml
- src/
- configuration/settings.xml

– add in settings.xml

openshift interpolates every *PROXY* environment variable stripping stuff, so you may not always be able to do


JBoss images support the following variables via the `assemble` script:


Another solution is to:

– get the assemble from the given image you’re using (different images, different assemble)
– customize it so that it uses environment variables to build a custom settings.xml to be used within the build
– add it to .s2i/bin/assemble

Here’s an example assemble supporting proxies

Jboss EAP: dumping configurations as scripts!

Today I found this nice tool to create configuration scripts for Jboss EAP from existing configurations.

$  git clone
$  cd profilecloner
$  export JBOSS_HOME=/opt/jboss/
$  mvn install
$  ln -s profilecloner.jar target/profile*jar
$  ./ -f save-script-here.cli  –controller=$HOST –username=admin –password=secret /profile=full-ha antani-new-profile-name
$  cat save-script-here.cli


Using custom CXF stack with JBoss EAP 6.x

Boss delivers a set of libraries as modules.

To use them you should reference them either in:

  • jboss-deployment-structure.xml

Those libraries can be publicly or privately exposed, as per
The list includes:

  • CXF 2.7.x
  • RestEasy
  • JBossWs

To use your custom stack as a JAXWS/RS implementation, you should specify in the jboss-deployment-structure.xml to:

  1. exclude webservices/jaxrs subsystem
  2. exclude JEE support: JAXRS is part of JEE specs and is a dependency of JEE
  3. exclude RestEasy and CXF modules
  4. eventually include, one-by-one, all the JEE dependencies you are going to use in your stack (eg. servlet)

An example app using the Jersey stack is here.

Per-class heap plots with py-jstack

Having to profile a webapp that filled the Java Heap, I wrote a simple python module that plots the size of the heap consumed by each class.

It uses the files generated by #jmap -histo $(pidof java); which tracks the memory per-class consumption.

Once you generate your files with something like:

while sleep 5; do
    jmap -histo $(pidof java) > /tmp/histo.$(date %s)

You can load the jplot module included in
Using ipython makes things even easier!

#git clone 
#cd py-jstack;
ipython$ import jplot

Once you loaded the module, you have to list the files to parse
and generate a table containing the classes and their memory occupation in time
for the first 30 greedy classes.

ipython$ files = ! ls /tmp/histo.*
ipython$ table = jplot.jhisto(files, limit=30, delta=False)

What does the `table` dictionary contain? A list of #instance and memory size in time

ipython$ cls = 'java.lang.String'
ipython$ print(table[cls][:10]) 
[(452588.0, 18103520.0), # values in 1st file
 (186198.0, 7447920.0), # values in 2nd file
 (229789.0, 9191560.0), # values in 3rd file
ipython$ memory_for_string = zip(*table[cls])[1]
ipython$ max_memory_for_string = max(memory_for_string)

Using matplotlib we can plot too, and have a glimpse of which class is misbehaving…

ipython$ jplot.plot_classes(table, limit=10)

Live debugging java with btrace

Today I had to do a live debugging on a java application. I found a nice tool named btrace (no, it’s not that btrace…but THIS btrace ;).

Btrace seems magical:

  1. is the java version of SystemTap or DTrace;
  2. doesn’t need java debugging nor has  further requirements;
  3. doesn’t stop your application.

Once downloaded, you have to:

  1. create a small java program specifying what to trace;
  2. find the pid of your target jvm instance;
  3. add the required classpath to btrace.

Then run it, with:

# ./btrace -cp $YOUR_CLASSPATH  $JVM_PID

The is something like this (example take from here):

import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
// every time new File(String) is called, print the file name
public class HelloBTrace {
clazz="", method=""
public static void onNewFile(File self, String name) {
print("new file ");


Java native logging a-la-printf with slf4j

Just saw that the new java logging framework slf4j supports parametrized logs, like“log this {} {} {} and {}”, 1,2,”three”,4);

More on

import org.junit.Test;
import org.junit.rules.TestName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LoggingTest {

@Rule public TestName name = new TestName();

final Logger logger =

public void testA() {"{} being run...", name.getMethodName());

public void testB() {"{} being run...", name.getMethodName()); }

We love partners ;)

I wonder why the “partner” repository is not enabled by default in ubuntu :P This repo enables sun-java and many other useful packages.

Shortly add to your /etc/apt/sources.list the following lines:

deb lucid partner
deb-src lucid partner

Logging a-la-printf with java

My C backgroud make me very unhappy when logging with java. I always have to type“Logging field %s: with value: %d”, field, value));

Today I decide to extend the default log4j logger implementing my & co using java varags.

I created two classes:

CustomLoggerFactory implements LoggerFactory:

  • @implement makeNewLoggerInstance(String name) return new MyLogger(name);

MyLogger extends Logger:

  • private MyLoggerFactory factory = new MyLoggerFactory();
  • @override getLogger(Class clazz)
  • info(String format, Object... params)

Now I can use MyLogger

MyLogger log = (MyLogger) MyLogger.getLogger(getClass());"Test base:string %s int %d" , "string", 0);

Further info here