Saturday, February 4, 2017

Gradle to Maven Convertion

Just need to add Maven plugin to build.gradle


Then run the command 'gradlew.bat install'

The pom file for maven build will be available under build/poms named 'pom-default.xml'

Copy the 'pom-default.xml' to build.gradle directory and rename to 'pom.xml'.

Now you can build project by maven command 'mvn clean install'

Indicate Java version

If the build is failed due to 'diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)', you need to add 'maven-compiler-plugin' to the pom file and re-run command 'mvn clean install'


Sunday, January 1, 2017

Java Post JSON data

GSON library is good tool to convert data to JSON format 1. Add GSON dependency, current latest version is 2.8.0 2. The data sender util look like:

How To Get Source IP Address from HttpServletRequest

The address of source of request is stored in the header of HttpServletRequest so it is simply to get it. If it is not available in header so we can get the RemoteAddress. Mark dependency to package javaee-web-api, current latest verion is 7.0 The util look like: