How to list all Jobs in the Quartz Scheduler

Below are two code snippets to show you how to list all Quartz jobs. Quartz 2 APIs are changed a lot, so syntax is different from Quartz 1.x. 1. Quartz 2.1.5 example Scheduler scheduler = new StdSchedulerFactory().getScheduler(); for (String groupName : scheduler.getJobGroupNames()) { for (JobKey jobKey : scheduler.getJobKeys(GroupMatcher.jobGroupEquals(groupName))) { String jobName = jobKey.getName(); String jobGroup …

Read more

How to get ServletContext in JSF 2

The ServletContext class is important in web application, often times, you need this class get the information of current deployed servlet container. Here’s a trick to show you how to get ServletContext in JSF2, via FacesContext. ServletContext servletContext = (ServletContext) FacesContext .getCurrentInstance().getExternalContext().getContext(); References ServletContext JavaDoc FacesContext JavaDoc

How to find a file in linux

In *nix, you can use the find command to find a file easily. $find {directory-name} -name {filename} 1. Find a file in the root directory If you have no idea where the file is located, you can search the entire system via the “/” root directory. Below example shows you how to find a file, …

Read more

Example to run multiple jobs in Quartz

In this example, we show you how to declare multiple Quartz jobs via Quartz APIs, Quartz XML and Spring. In Quartz scheduler framework, each job will be attached to an unique trigger, and run it by scheduler. P.S In Quartz, one trigger for multiple jobs is not possible. (Correct me if this is wrong.) 1. …

Read more

Quartz Scheduler Tutorial

Quartz, is a open source job scheduling framework, that let you scheduler a task to run on a predefine date and time. Happy learning Quartz 🙂 1. Quick Start Hello world to Quartz scheduler frameworks. Quartz 1.6 hello world example The old and popular Quartz 1.6.3, legacy system may still using this. Quartz 2 hello …

Read more

JSF 2 + Quartz 2 example

In this tutorial, we show you how to run a Quartz job during JSF web application via QuartzInitializerListener listener class in Quartz library. This solution is not only works with JSF 2, the concept is applicable on almost all standard Java web application. Tools Used : JSF 2.1.11 Quartz 2.1.5 Maven 3 Eclipse 4.2 Tomcat …

Read more

How to work with Java 6’s NavigableSet and NavigableMap

You can use latest Java 6’s Collection API to navigate a set and Map collections. These API gives a lot of flexibility to find out required result from the collection. 1. NavigableMap Example package com.example.collection; import java.util.NavigableMap; import java.util.TreeMap; public class NavigableMapDemo { public static void main(String[] args) { NavigableMap<String,Integer> navigableMap=new TreeMap<String, Integer>(); navigableMap.put("X", 500); …

Read more

IncompatibleClassChangeError : JobDetailBean has interface org.quartz.JobDetail as super class

Developing Quartz 2.1.5 + Spring 3.1.2.RELEASE, hits following error messages : Caused by: java.lang.IncompatibleClassChangeError: class org.springframework.scheduling.quartz.JobDetailBean has interface org.quartz.JobDetail as super class at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631) at java.lang.ClassLoader.defineClass(ClassLoader.java:615) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2901) at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1170) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) at org.springframework.util.ClassUtils.forName(ClassUtils.java:258) … 19 more Solution Quartz 2 APIs are changed a lot, and someone already …

Read more

java.lang.ClassNotFoundException: org.springframework.transaction.TransactionException

Developing Quartz with Spring 3, and hits following error message. Caused by: java.lang.NoClassDefFoundError: org/springframework/transaction/TransactionException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389) at java.lang.Class.getConstructor0(Class.java:2699) at java.lang.Class.getDeclaredConstructor(Class.java:1985) ….. Caused by: java.lang.ClassNotFoundException: org.springframework.transaction.TransactionException at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556) … 29 more Solution Doesn’t matter with Quartz, above error message show that you need Spring transaction dependency. To fix it, just include …

Read more

How to use reflection to copy properties from Pojo to other Java Beans

Sometimes we need copy properties from a Java class to other, we can do it this manually or with our own reflection implementation, but in this case use us reflection for automate it with a utility from apache Requirements commons-beanutils , you can download from here http://commons.apache.org/beanutils/ commons-loging , you can download from here http://commons.apache.org/logging/ …

Read more

How to get last Tweet via jQuery

Twitter, provides many APIs to deal with Tweets. In this example we are going to learn how to use jQuery to get last tweet of a user. Twitter API Get the last tweet of user (change “username” in the url with Twitter username you want) http://search.twitter.com/search.json?q=from:username&rpp=1 For example, get last tweet from twitter’s user “mkyong”. …

Read more

How to run a task periodically in Java

Some java application need to execute a method between a regular interval of time. For example GUI application should update some information from database. 1. Scheduler Task For this functionality, You should create a class extending TimerTask(available in java.util package). TimerTask is a abstract class. Write your code in public void run() method that you …

Read more

Custom jQuery plugin and CSS to display and hide content

The requirement : We need to show a collapsable content when we clicked ‘Show’ button, and hide the collapsable content when we clicked ‘Hide’ button. The solution : Create a custom jQuery plugin. Demo : Clicks on the “show” button. Note Here’s the alternative solution – jQuery toggle() function. 1. Collapsable content Below is an …

Read more

Eclipse IDE – Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules

Problem Import a Java web project in Eclipse, build with Maven, once create a Tomcat server instance, unable to add the Java web project, and showing Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules Tools used : Eclipse Juno 4.2 Tomcat 6.0.35 JDK 1.6 Solution In project, “.settings” …

Read more

jQuery toggle example to display and hide content

The requirement : We need to show a collapsable content when we clicked ‘Show’ button, and hide the collapsable content when we clicked ‘Hide’ button. The solution : jQuery toggle() function. Demo : Clicks on the “show” button. 1. Collapsable Content Below is an example of HTML for collapsable content: <section class="round-border"> <h2>Use jQuery toggle …

Read more

jQuery – watermark effect on text input

A simple jQuery example to show you how to implement a watermark text effect on an input field. 1. Code Snippets An email input field and css watermark class. <style type="text/css"> input.watermark { color: #999; } //light silver color </style> <label>Email : </lable> <input id="email" type="text" /> jQuery to apply the watermark effect on email …

Read more

Quartz 2 JobListener example

In this tutorial, we will show you how to create a JobListener, to keep track the running jobs status, like when the job is finished. P.S This example is tested with Quartz 2.1.5 1. Quartz Job Job, print a simple message, and throw a JobExecutionException for testing. File : HelloJob.java package com.mkyong.quartz; import org.quartz.Job; import …

Read more

Quartz 2 scheduler tutorial

Quartz, enterprise scheduler job framework, to help Java application to scheduler a job/task to run at a specified date and time. This tutorial show you how to develop a scheduler job using latest Quartz library 2.1.5. Note Quartz 2 involves significant API changed, read this for older Quartz 1.6.3 example. 1. Download Quartz You can …

Read more

Java and zip code example

Recently, answered an question about leading zero problem ZipCode, what is the most proper data type for country’s zip code? 1. ZipCode – int In Java, some claimed it should declare as “int”, and use DecimalFormat to format and display the leading zero. For example, package com.mkyong; import java.text.DecimalFormat; public class ZipCodeExample { public static …

Read more

Quartz : org.quartz.SchedulerConfigException: Thread count must be > 0

Working with Quartz 2, when running the project, hits following error message? org.quartz.SchedulerConfigException: Thread count must be > 0 at org.quartz.simpl.SimpleThreadPool.initialize(SimpleThreadPool.java:245) at org.quartz.impl.StdSchedulerFactory.instantiate(StdSchedulerFactory.java:1255) at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1484) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) at java.util.concurrent.FutureTask.run(FutureTask.java:138) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:680) Solution You have defined a “quartz.properties” file, and override the …

Read more

How to get URL content in Java

In this Java example, we show you how to get content of a page from URL “mkyong.com” and save it into local file drive, named “test.html”. package com.mkyong; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class GetURLContent { public static void main(String[] args) …

Read more

Google App Engine Tutorial

Google App Engine, a cloud computing platform for hosting web application in existing Google infrastructure, it’s easy to scale, manage and free to use up to a predefined consumed resources, and it supports Java. For additional charged, please refer to this GAE billing . In this series of tutorials, we will show you a list …

Read more

Google App Engine + JDO + Spring MVC, CRUD example

Note This tutorial is more on practice guide, please refer to this official Using JDO in datastore for detail explanation. See following code snippets to perform CRUD on GAE datastore, using Java Data Objects(JDO). Just annotate the Customer with JDO annotation and perform the CRUD via PersistenceManager. Add Customer c = new Customer(); c.setName(name); PersistenceManager …

Read more

Google App Engine + Spring MVC, CRUD example with datastore low level api

GAE datastore Refer to this official “Using datstore guide” to understand what is GAE datastore. See following code snippets to perform CRUD for Google App Engine datastore, Java, using low-level API. Add Store a customer into datastore, with “name” as the key. Key customerKey = KeyFactory.createKey("Customer", "your name"); Entity customer = new Entity("Customer", customerKey); customer.setProperty("name", …

Read more

Download / export Google App Engine Logs, Java App

In GAE, Java App, you can use command “appcfg request_logs” to download or export the logs from GAE to your computer, see signature below : AppCfg [options] request_logs <app-dir> <output-file> You can type “appcfg request_logs” to view all available options. 1. What is <app-dir> ? This is NOT your app_id nor any deployed web path …

Read more

Configure logging in Google App Engine

Google App Engine for Java is using java.util.logging.Logger to perform the logging. In this tutorial, we show you how to do logging in GAE environment. 1. Logging Example Example to define a logger in MovieController, and log the messages in different logging levels (info, warning and error) import java.util.logging.Logger; //… @Controller @RequestMapping("/movie") public class MovieController …

Read more

Add maxlength on textArea using jQuery

The “maxlength” attribute is not supported in textArea, but you can use JavaScript to limit the length of textArea dynamically. HTML 5 The textArea “maxlength” attribute is supported in HTML 5, the problem is not all browsers support HTML 5, especially, the old IE. jQuery Example A jQuery example to implement the “maxlength” effect on …

Read more

How to install gcc compiler on Mac OS X

Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn’t install the gcc compiler by default. If you try to install or compile some projects that required c/gcc compiler, following errors message will be logged : configure: error: C compiler cannot …

Read more

Google App Engine + JSF 2 example

In this tutorial, we will show you how to develop and deploy a JSF 2.0 web application in Google App Engine (GAE) environment. Tools and technologies used : JDK 1.6 Eclipse 3.7 + Google Plugin for Eclipse Google App Engine Java SDK 1.6.3.1 JSF 2.1.7 Note This example is going to reuse this JSF 2.0 …

Read more

Google App Engine + Struts 1 example

Long live classic Struts 1 framework, in this tutorial, we will show you how to develop a Struts 1.x web application in Google App Engine (GAE) environment. Tools and technologies used : JDK 1.6 Eclipse 3.7 + Google Plugin for Eclipse Google App Engine Java SDK 1.6.3.1 Struts 1.3.10 Note You may also interest at …

Read more

Google App Engine + Struts 2 example

In this tutorial, we will show you how to develop Struts 2 web application in Google App Engine (GAE) environment. Tools and technologies used : JDK 1.6 Eclipse 3.7 + Google Plugin for Eclipse Google App Engine Java SDK 1.6.3.1 Struts 2.3.1.2 Note Before proceed on this tutorial, make sure you read this – GAE …

Read more

GAE + JSF : Unable to instantiate ExpressionFactory ‘com.sun.el.ExpressionFactoryImpl’

Problem JSF application is able to deploy on local GAE environment, with following development environment : JSF 2.1.7 Google App Engine SDK 1.6.3 But hit error message while deployed on GAE production environment. Below is the logged error messages from GAE. com.sun.faces.config.ConfigureListener installExpressionFactory: Unable to instantiate ExpressionFactory ‘com.sun.el.ExpressionFactoryImpl’ E 2012-04-24 03:37:37.989 com.sun.faces.config.ConfigureListener contextInitialized: Critical error …

Read more