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 Grable 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

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

jsoup

jsoup : Send search query to Google

This example shows you how to use jsoup to send a search query to Google. Document doc = Jsoup .connect("https://www.google.com/search?q=mario"); .userAgent("Mozilla/5.0") .timeout(5000).get(); Unusual traffic from your computer network Don’t use this example to spam Google, you will get above message from Google, read this Google answer. 1. jsoup example ExampleContinue Reading

java_logo_100

Java – Read a file from resources folder

In this tutorial, we will show you how to read a file from a resources folder, in both Java and Unit Test environment. In simple, put files in a resources folder, and read the file with following code snippets : ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("file/test.xml").getFile()); 1.Continue Reading

tomcat-logo

How to change Tomcat manager default path ?

By default, Tomcat’s manager webapp is able to access via yourapp:8080/manager. It is a good practice to change the default /manager to something else, to avoid potential brute force attack. Environment Tomcat 7 (apt-get install) Debian 7.5 1. Solution This article show you how to change / rename the defaultContinue Reading

tomcat-logo

How to change Tomcat to use JDK 7

The current environment is using Tomcat 7 + JDK 1.6. Installed a JDK 1.7, but how to tell Tomcat to use the latest JDK? Environment Tomcat 7 (apt-get install) Debian 7.5 JDK 6 and JDK 7 1. Solution By default, Tomcat will pick up the JDK which configured in theContinue Reading

Page 1 of 9712345...102030...Last »