log4j logo

Maven – Exclude log4j.properties in Jar file

This example shows you how to use Maven to exclude the log4j.properties file from your Jar file. Note Please, DO NOT include the log4j.properties into the final Jar file, it will cause multiple log4j.properties files in the classpath, if someone is depending on your Jar, you may accidentally override theirContinue Reading

java jar with maven

Maven – Create a fat Jar file – One-JAR example

In this tutorial, we will show you how to use Maven build tool, One-JAR plugin to create a single Jar together with its dependency Jars into a single executable Jar file, so called fat Jar. Tools used : Maven 3.1.1 JDK 1.7 Joda-time 2.5 1. Create a simple Java projectContinue Reading

java_logo_100

Java – Cron job to run a jar file

Quartz is good, but often times we just need a simple scheduler system to run a jar file periodically. On *unix system, you can use the build-in cron to schedule a scheduler job easily. In this example, we will show you how to create a cron job on *nix toContinue Reading

gradle-logo

Gradle – How to skip unit test

Be default, Gradle build is abort if any unit tests is failed. Oftentimes, we still need to build the project even the unit test is failed. To skip the entire unit tests in Gradle build, uses this option-x test gradle build -x test Review a sample output : 1. DefaultContinue Reading

spring-logo

Gradle – Spring MVC Web Project Example

In this tutorial, we will show you how to create a Spring MVC web project (JSP view), and manage it by Gradle. Technologies and Tools : Gradle 2.0 Spring 4.0.6.RELEASE Eclipse 4.4 1. Project Structure Create following folder structure : ${Project}/src/main/java ${Project}/src/main/resources ${Project}/src/main/webapp ${Project}/src/test/java ${Project}/src/test/resources ${Project}/build.gradle 2. Gradle Build CreateContinue Reading

eclipse-logo

How to configure hot deploy in Eclipse

In this tutorial, we will show you how to configure Eclipse debugger to support hot deploy, hot swap or hot code replace without restarting the Server, this speed development a lot. Environment : Eclipse 4.4 (Supported in older version as well) Eclipse Tomcat Plugin 1. Hot deploy example Review aContinue Reading

gradle-logo

Gradle – Create a Jar file with dependencies

In this tutorial, we will show you how to use Gradle build tool to create a single Jar file with dependencies. Tools used : Gradle 2.0 JDK 1.7 Logback 1.1.2 1. Project Directory Create following project folder structure : By default, Gradle is using the standard Maven project structure. ${Project}/src/main/java/Continue Reading

gradle-logo

Gradle – bootstrap class path not set in conjunction with -source 1.5

My environment : JDK 1.7 Eclipse 4.4 Gradle 2.0 While gradle builld the project, I get following compile warning message : :compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.5 1 warning Figure : Eclipse console view. Solution The warning is saying you are using JDK 1.7,Continue Reading

gradle-logo

Gradle : Add Eclipse project nature

Eclipse project natures are configured in the .project file. For example : .project <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>hello</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.springsource.ide.eclipse.gradle.core.nature</nature> <nature>org.eclipse.jdt.core.javanature</nature> </natures> </projectDescription> To add a nature, just modify the nature tag, and add whatever nature you want. In Gradle,Continue Reading

maven-logo

Maven – Exclude logback.xml in Jar file

This example shows you how to use Maven to exclude the logback.xml file from the final Jar file. Note Please, DO NOT include the logback.xml into the final Jar file, it will cause multiple logback.xml files in the classpath, if someone is using your Jar, you may override other’s loggingContinue Reading

nginx-logo

Nginx : Block Referrer Spam

In this article, we will show you how to block referrer spam in one of our Nginx web server. 1. Find the Patterns Check the Nginx access.log file, and identify the “referrer spam” patterns. $ sudo tail -f /var/log/nginx/access.log Some patterns : 200 http://???.ru/engine/redirect.php?url=http://mywebsite.com/site/blogspot.com.au 200 http://???.com/tp/out.php?link=alternatevideo&url=http%3A//mywebsite.com/site/readyliftproshop.com 200 http://???.edu/online/redirect.asp?url=http://mywebsite/site/wheretoshophongkong.com We areContinue Reading

nginx-logo

Nginx + Apache Tomcat configuration example

This tutorial shows you how to configure Nginx as a reverse proxy to redirect the traffics from port 80 to Apache Tomcat on port 8080. Here is the environment in my Linode server : Debian 7.5 Nginx 1.2.1 Tomcat 7.0.28 P.S Both Nginx and Tomcat are installed via apt-get install.Continue Reading

java-random-number

Java : Return a random item from a List

Normally, we are using the following ways to generate a random number in Java. 1. ThreadLocalRandom (JDK 1.7) //Generate number between 0-9 int index = ThreadLocalRandom.current().nextInt(10); 2. Random() //Generate number between 0-9 Random random = new Random(); int index = random.nextInt(10); 3. Math.random() //Generate number between 0-9 int index =Continue Reading

nginx-logo

Nginx : Block User Agent

In Nginx, you can block certain user agents (normally it is crawler) like this : /etc/nginx/sites-enabled/default server { listen 80; server_name mysite.com; root /etc/tomcat7/webapps/mysite;   if ($http_user_agent ~* (ahrefs|wget|crawler|majestic) ) { return 403; }   location / { <!– xxx –> } } In above example, for “user agent” thatContinue Reading

nginx-logo

Count IP address in Nginx access logs

Recently, many referer spam hit on my server, below is the command I used to find and count the IP Address from a Nginx access log file. $ sudo awk ‘{print $1}’ /var/log/nginx/access.log | sort | uniq -c | sort -nr Full example. $ sudo awk ‘{print $1}’ /var/log/nginx/access.log |Continue Reading

Page 1 of 9812345...102030...Last »