Adding dependencies from local Maven repositories to Activator projects

As I’m using in my Activator/Play Framework project a few jars which I build separately using maven, I want to the activator build tool to search for the dependencies in my maven local repositories. In order to do so, include the following lines in build.sbt tool:

resolvers ++= Seq (

Once you build a jar via “mvn package” and push it to the local repository using “mvn install” comman, Activator SBT tool will look for it in that location.

If Sbt is not able to find the maven local repository location, you can specify the path directly:

resolvers ++= Seq (
“Sonatype OSS Snapshots” at “”

More Details in SBT Manual.

Retrieving Files Recursively in Java

Sometimes I need to read recursively all the files from a directory. I kept using DirectoryScanner class from the Apache(located in ant.jar in my case). It has the advantage that it can filter through files based on the well-known asterisk matching. Recently I had to look-up in a directory containing lots and lots of files and it proved DirectoryScanner tended to be quite slow. So I used plain java for that(using and classes), for 2 reasons. First is that the speed can be improved quite easy. The second reason is that reporting progress in command line give the impression it takes less time.
Continue reading

Getting SunCertPathBuilderException when sending mail from Java via SSL?

Do you get SunCertPathBuilderException: unable to find valid certification path to requested target when you try to send a mail from java via smtp(TLS and SSL)? There are 2 possible problems:

  • One option could be from the antivirus/firewall which prevent the communication for a specific port(default 465 for SSL and 587 for TSL) or for the java.exe. In the case you have a recent JDK/JRE and you use a well-known service this is probably the problem. Just try to disable the antivirus and to send again the mail from java. If it doesn’t work check the next point
  • You have an invalid/expired certificate for the email server so the SSL/TLS authentication doesn’t work properly. In order to overcome this you have to install the valid certificate.
  • Continue reading

    How To Resize/Convert Images In Java

    Java comes by default with some classes to manipulate images. Those classes are located in java.awt package and are intended to be used for awt applications. For this reason they are not too rich in functionality to have enough options to control the resize quality. In the following snippet BufferedImage and ImageIO can be used to load an image in memory and to convert it to different format: Continue reading

    How To Use JDBC addBatch Method with MySQL for Improved Performance

    [tweet-dzone]When you have to deal with a large amount of data to be operated on mySQL databases, the performance can be dramatically improved using a few simple tweaks.

    First of all you have to use Statement.addBatch/executeBatch instead of simple execute methods. For each added batch, the jdbc driver will store in local memory and when the executeBatch is invoked, all the batches are sent at once to the database. This will result in an huge speed improvement.
    Continue reading

    How To Download a File in Java

    Here is a snippet that shows how to download a file in java. The snippet is tested and works just fine:

    	static public void download(String address, String localFileName) 
    											throws MalformedURLException
    												 , FileNotFoundException
    												 , IOException
    		URL url = new URL(address);
    		OutputStream out = new BufferedOutputStream(
    								new FileOutputStream(localFileName));
    		URLConnection conn = url.openConnection();
    		InputStream in = conn.getInputStream();
    		byte[] buffer = new byte[1024];
    		int numRead;
    		int progress = 0;
    		while ((numRead = != -1) {
    			out.write(buffer, 0, numRead);
    			progress += 1024;
    			System.out.print("\r" + (int)(progress / 1000)+ "kb");

    How to use Post Method using Apache HttpClient 4

    [tweet-dzone]HttpClient is an apache java library that can be used to read pages over http. It can be used mainly for webpages and provide a well defined API that can handle Cookies, Sessions,… It offers support for both Get and Post methods, so it’s very useful for writing http java clients that can login and perform different actions on webpages.

    Starting with the version 4 the classes were drastically changed. Old tutorials don’t works anymore and the class names and methods were changed to some degree which makes old code pretty useless if you want to switch to a version 4.
    Continue reading