The following piece of Java code could convert a date string into a Unix timestamp.
String dateString = "Fri, 09 Nov 2012 23:40:18 GMT";
DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss z");
Date date = dateFormat.parse(dateString);
long unixTime = (long)date.getTime()/1000;
System.out.println(unixTime); //<- prints 1352504418
The Apache Commons Lang library could help you to determine the running OS type. Here is an simple example.
Continue reading Java – Determine if the running OS is Windows, Mac or Linux
Previously we have talked about how to package a .jar artifact with dependencies included.
An alternative solution is to put your dependencies in the src/main/resources folder and they will be copied to the target folder together with the packaged .jar file. Then we can add the class paths to these dependencies in the Manifest with the help of the maven-jar-plugin.
The following project is a real life example which i use it to test the connection between the JBoss server and the MSSQL server.
Continue reading Maven – Add Java classpath to manifest for runtime
Jenkins, previously named as Hudson, is a continuous integration tool just like CruiseControl. It has been almost 4 years since i started learning Maven which made me fall in love about best practice. Deployment and testing automation is really fun and finally i got a chance to play it again.
In this article, i would show you how to setup a simple Ant build project in Jenkins. Before we start, please refer to the simple Java project example in the post below.
1. Download and install Jenkins.
Continue reading Jenkins – Setup a simple Ant build project
Haven’t worked with Apache Ant for a long time. It’s time to pick up it again. Here is a simple Java project could be built by Ant.
Continue reading Apache Ant – A simple Ant build project
The Apache Commons Codec could help you to generate the MD5 of a file with just one command. Download the lib @ Download Commons Codec. If you want to use Maven, include the following dependency in the pom.xml. Continue reading Java – Get MD5 Checksum of a File
Yesterday we try to zip a folder in Java.
Java – Zip Folder Recursively
So now we need to unzip it. Create the following Java class and try. Continue reading Java – Unzip
This example shows you how to do date comparison in Java. Continue reading Java – Date Comparison
Long time ago, i have a post about date validation in Java using SimpleDateFormat.
Java – Date validation using SimpleDateFormat
The SimpleDateFormat can format a Date object into string. See the following example. Continue reading Java – Convert Date to Formatted String