Showing posts from 2017

Read a text file in only one line of Java code

Since Java 7, you can do this with this wonderfull line :

new String(Files.readAllBytes(Paths.get(this.getClass().getResource("/file.txt").toURI())))

That makes Java powerfull and I love that.

Oracle 12c column alias length limit workaround

Oracle, in older version, has some limitations on column alias name length. You cannot exceed 30 characters. On my project, I use Hibernate to access database and everythings work when Hibernate plays in SQL. But, my colleague who tried to grab some data from a PL/SQL script had the following error :

ORA-00972 : Identifier is too long
Humm...  F***! So, three solutions to solve this issue :

ask your DBA to migrate to Oracle 12cR2  which allows column alias names up to 128 charactersalter your database and change your application to fit this new shorter namefind a working workaround !!!!
Here is this workaround : the idea is to make a virtual column which contains the same data but with a shorter alias name.  Example : 
alter table MYTABLE add NEW_COL date generated always AS (MY_COL_WITH_VERY_LONG_NAME - 0) virtual;
The value in the virtual column must be calculated. The trick is to make a dummy operation (like value-0). 
Whooo... that's cool. So cool that I wanted to make other oper…

Kill Linux process that consumes all memory

Found on SatckOverFlow. I love it :

ps -eo pid --no-headers --sort=-%mem | head -1 | xargs kill -9 With: ps -eo pid --no-headers --sort=-%mem: display the process ids of all running processes, sorted by memory usagehead -1: only keep the first line (process using the most memory)xargs kill -9: kill the process

Install VMware Horizon Client (VMware View) on Ubuntu

If like me, you had issues with VMware horizon client package on your Ubuntu desktop, here are my tips.

Step 1 : download the installation package

Step 2 : make it executable and run it

chmod +x VMware-Horizon-Client-*******.x64.bundle
sudo ./VMware-Horizon-Client-*******.x64.bundle

This will install files but it's not runnable because you need some libs.

Step 3 : find and fix libs not found

To view needed libs, run : ldd /usr/lib/vmware/view/bin/vmware-view

Results is something like : =>  (0x00007ffdb45e6000) => /usr/lib/x86_64-linux-gnu/ (0x00007fcb631a6000) => /usr/lib/x86_64-linux-gnu/ (0x00007fcb62f84000) => /usr/lib/x86_64-linux-gnu/ (0x00007fcb62938000) => /usr/lib/x86_64-linux-gnu/ (0x00007fcb6268…

Declare secured connector on Tomcat for https connections

To access your tomcat threw https, you have to declare a secured connector. There are two parts to do that :

modify your server.xml with the new connector configurationgenerate a java keystore the connector will refer to
Step 1 : Modify your serveur.xml like this

<Connector            protocol="org.apache.coyote.http11.Http11NioProtocol"            port="${ssl.port}" maxThreads="200"            scheme="https" secure="true" SSLEnabled="true"            keystoreFile="${java.home}/lib/security/tomcat_java.keystore" keystorePass="changeit"            clientAuth="false" sslProtocol="TLSv1.1" ciphers="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_S…

Acces Apache Tomcat on port 80 or 443 from Linux

Default Linux security rules don't allow to access network ports < 1024 to non rooted processes. A bad idea would be to start your Tomcat as ROOT. Very bad idea!!! But these's another solution. You can start your Tomcat with a port > 1024 and then redirect requests from standard ports (such as HTTP/80  or HTPS/443) to ports > 1024.

Let's imagine you bound Tomcat https connector to 8301. We'll add a rule to iptables like this :

Prequisites : switch to root (su -)

iptables -A PREROUTING -t nat -i eth1 -p tcp --dport 443 -j REDIRECT --to-port 8301
/etc/init.d/iptables save
/etc/init.d/iptables restart

Then, just check if rule is active with iptables -L

target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https

Now, you can access your tomcat threw a classic https url :)

Use Spring profiles and yaml configuration without Spring Boot

That's a refinement you can do to updgrade legacy applications. Using yaml config files combines with Spring profiles is a great way to configure your apps. Let's see how to do that.

Firstly, let's consider that we weill inject something in a java class depending on the runtime  environment.

public class MyService {

private String URL;


application.yaml should be like this :


  profiles: production


Thus, if I lauch my applicatin without JVM Spring profile params, URL will be If I launch it with, URL will be Great! But this feature is natively supported only for Spring Boot based applications. So, let's active this on legacy apps with this XML spring config file fragment :
<bean id="yamlProperties" class="o…

Install Oracle Java Development Kit on Ubuntu

First of all, you need to download it from Oracle web site

Then unzip it somewhere (be carefull that location is reachable from users who would use java)

tar xvzf jdk-*-linux-x64.tar.gz

The fun part would be here...

You should set your JAVA_HOME. Set it in your /etc/environment for every users or .profile for your current user

Now, we will create two symbolic links for java and javac command using update-alternatives command. There's two steps : install and set. The first create a symbolic link and register it to etc/alternatives with its alias. The second actives this alias. So, let's do this :

sudo update-alternatives --install /usr/bin/java java /home/..../jdk*/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /home/..../jdk*/bin/javac 1

sudo update-alternatives --set java /home/..../jdk*/bin/java
sudo update-alternatives --set javac /home/..../jdk*/bin/javac