Mainly Spring/Java and Java JEE tips and tutorials based on what i'm working on, usually (Spring, MongoDB, Spring boot, Big Data, Cassandra etc.) or what interests me.
Occasionally some gadget tips.
As covered in a previous article (here and here) spring-boot is a very useful framework when working on full enabled Spring projects
Recently I wasted some time with yet another encoding problem.. where all my accentuated and special characters where corrupted.
I was using the data.sql convention that states that if a file named data.sql is found in the CLASSPATH spring will use this file to bootstrap the database, my SQL file was properly encoded in UTF-8 as well as my maven-resources-plugin however the data recovered from the database was corrupted (accents and special characters where broken)
After reading a bit the documentation I found out that the source of the problem was at the moment of reading the SQL file that the encoding was causing trouble.. thankfully you can fix this one pretty easlily by changing one property value :
spring.datasource.sqlScriptEncoding=UTF-8
spring-boot has a lot of useful properties that allow you to tune the framework which you can find here
It's not uncommon to need a custom packaging or assembly for a given project for some reason or another, this can be accomplished in a certain number of ways
Recently I needed an application to be packaged as the following structure :
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
Your project can build distribution assemblies easily, using one of the convenient, prefabricated assembly descriptors.
These descriptors handle many common operations, such as packaging a project's artifact along with generated documentation into a single ZIP archive. Alternatively, your project can provide its own descriptor and assume a much higher level of control over how dependencies, modules, file-sets, and individual files are packaged in the assembly.
Currently the plugin can create distributions in the following formats:
zip
tar
tar.gz
tar.bz2
jar
dir
war
format that the ArchiveManager has been configured
For this tutorial we will be using the dir format in order to output the project structure described above
Let's start with the easy part first, the maven assembly plugin configuration where we will tell the plugin where to find our assembly file and where to output the result of the assembly operation
Now since in our case we want all the files in the resource directory to be handled by the assembly plugin we will configure the maven resources plugin to ignore everything inside the resources folder (please note that this is an optional step and it might not apply to your project)
...
${basedir}/src/main/resources**/**
...
Once the maven part is done we can get started with the core code
If you remember we will end up with a runnable JAR file so go ahead and create a Main class like so :
package com.ufasoli.maven.custom.assembly;
/**
* User: Ulises Fasoli
* Date: 23.06.2014
* Time: 18:03
* Project : maven-custom-assembly
*/
public class Main {
public static void main(String[] args) {
System.out.println("HELLO WORLD !");
}
}
Since this is going to be a runnable JAR file we will need to configure the maven JAR plugin to generate the manifest file with our main class