Category Archives: J2EE

Java program to convert a image into PowerPoint PPT

Here is the Java program that converts (uploads) images into PowerPoint .PPT file using Apache POI libraries.

Use (download) the following combination of Apache POI libraries,

poi-3.11-20141221.jar and poi-scratchpad-3.8.jar

Let’s jump into the program

package com.athavan.examples;

import java.awt.Dimension;

import org.apache.poi.hslf.model.Fill;
import org.apache.poi.hslf.model.Picture;
import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.SlideShow;

public class CreatePresentation {

private SlideShow ppt;
private Slide slide;
private Fill fill;
private int idx;
private FileOutputStream out;

public static void main(String[] args) {
CreatePresentation cp = new CreatePresentation();
try {
cp.ppt = new SlideShow();
cp.ppt.setPageSize(new Dimension(100, 50));
cp.out = new FileOutputStream(

// use the for loop if you have many images to be uploaded into PPT

// for (int k = 0; k < 1; k++) {
String tmp = "G:\\Saravanan\\Pulse\\Software.PNG";
cp.createSlideWithChart(cp, tmp);
// }
// Save PPT
} catch (Exception fnfe) {

public void createSlideWithChart(CreatePresentation cp, String chartName) {
try {
slide = cp.ppt.createSlide();
fill = slide.getBackground().getFill();
idx = cp.ppt.addPicture(new File(chartName), Picture.PNG);
} catch (FileNotFoundException fnfe) {
} catch (IOException ioe) {


Input File: Software.PNG
Output File: slideshow2.ppt


The above program converts a image into PPT. If we want to upload more images in a folder into PPT, then we can have for loop (which is commented) to achieve the same.

Happy learning and sharing… 🙂

Exception in thread “main” java.lang.NoSuchFieldError: filesystem at org.apache.poi.hslf.HSLFSlideShow.getPOIFSFileSystem(

I was trying to convert a image into PPT using JAVA with the help of Apache POI libraries.

I got the below exception

Exception in thread "main" java.lang.NoSuchFieldError: filesystem
at org.apache.poi.hslf.HSLFSlideShow.getPOIFSFileSystem(
at org.apache.poi.hslf.EncryptedSlideShow.checkIfEncrypted(
at org.apache.poi.hslf.HSLFSlideShow.(
at org.apache.poi.hslf.HSLFSlideShow.(
at org.apache.poi.hslf.HSLFSlideShow.(
at org.apache.poi.hslf.HSLFSlideShow.create(
at org.apache.poi.hslf.usermodel.SlideShow.(
at com.athavan.examples.CreatePresentation.main(


I was using poi-3.11-20141221.jar and poi-scratchpad-3.2-FINAL.jar. That’s went wrong here. Then I replaced the poi scratchpad with latest version, the error gone.

poi-scratchpad-3.8.jar worked well.

poi-3.11-20141221.jar and poi-scratchpad-3.8.jar combinations worked!!

Happy learning and sharing 🙂

java.lang.IllegalStateException: Web app root system property already set to different value: ‘webapp.root’ = [/ApplicationPath1] instead of [/ApplicationPath2] – Choose unique values for the ‘webAppRootKey’ context-param in your web.xml files!

Recently I have deployed two J2EE web application in tomcat web server. Both application uses the log4j. Tomcat server is up and running with no issues.

But at regular interval, one of the J2EE web application was going down. I was digging into the logs and google to find the solution. At regular times, it made us to enter into the tomcat manager page to start the application manually which was down.

Then I have identified the following exception message

java.lang.IllegalStateException: Web app root system property already set to different value: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat7.0.57\webapps\application1\] instead of [C:\Program Files\Apache Software Foundation\Tomcat7.0.57\webapps\application2\] - Choose unique values for the 'webAppRootKey' context-param in your web.xml files!
at org.springframework.web.util.WebUtils.setWebAppRootSystemProperty(
at org.springframework.web.util.Log4jWebConfigurer.initLogging(
at org.springframework.web.util.Log4jConfigListener.contextInitialized(
at org.apache.catalina.core.StandardContext.listenerStart(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
at org.apache.catalina.core.ContainerBase.addChildInternal(
at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(
at org.apache.catalina.startup.HostConfig.deployDirectory(
at org.apache.catalina.startup.HostConfig$
at java.util.concurrent.Executors$ Source)
at Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$ Source)
at Source)

Root cause:

Due to the business requirement, we copied the application1’s code base and created the application2’s code base.
I gave unique names wherever necessary in the configuration files. But still I encountered the above error message. After spending long time, I got the below information about the spring framework

“WARNING: Some containers (like Tomcat) do not keep system properties separate per web app. You have to use unique “webAppRootKey” context-params per web app then, to avoid clashes. Other containers like Resin do isolate each web app’s system properties: Here you can use the default key (i.e. no “webAppRootKey” context-param at all) without worrying. ”

It turns out that the webAppRootKey is a Spring context parameter. It exposes the web application’s root directory as a system property. So, it is the value of the webAppRootKey that provides the name for the system property to use. That’s fine if you’ve just got one webapp in Tomcat. Spring will just choose a default value for this (app.root) and off you go. However, as the warning above notes, Tomcat does not keep system properties separate per webApp. This means that when we get to the second application, the same system property (app.root) is being set to a new value (our second application’s root directory, rather than the first!)

The reason this is occurring at all is that Log4JConfigListener is trying to set the webAppRootKey in both cases. This allows log4J to place log and config files in directories relative to the application root directory, rather than in a fixed path.

I decided the easiest thing was just to use a non-default name for the webAppRootKey for each of my applications.

That is, I fixed this by placing the following context-parameter into each of the web application’s web.xml files:


This fixed the problem

Where can we download Spring Framework Jars?

We can download Spring JARs as .zip from the following link

Cheers 🙂

how to pass LIKE parameters (values) in NamedParameterJdbcTemplate in Spring

Imagine we have a query


As we are using NamedParameterJdbcTemplate, I’d like to pass title as a parameter named title holding the value.

So the query would now be SELECT * FROM ARTICLE WHERE TITLE LIKE ‘%:title%’

We have to frame the query as like below in Spring JDBC Code

String final GET_QUERY = "SELECT * FROM ARTICLE WHERE TITLE LIKE '%'||:title||'%'";

So, in our spring code

MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("title", title);

NamedParameterJdbcTemplate npjt = new NamedParameterJdbcTemplate(
list = npjt.query(
GET_QUERY, parameters,
new RowMapper() {....});

EhCache.xml Configuration

CacheManager Configuration
An ehcache.xml corresponds to a single CacheManager. See instructions below or the ehcache
schema (ehcache.xsd) on how to configure. System property tokens can be
specified in this file which are replaced when the configuration is loaded.
For example multicastGroupPort=${multicastGroupPort} can be replaced with the
System property either from an environment variable or a system property
specified with a command line switch such as -DmulticastGroupPort=4446.

DiskStore configuration
The diskStore element is optional. To turn off disk store path creation, comment out the diskStore element below. Configure it if you have overflowToDisk or diskPersistent
enabled for any cache. If it is not configured, and a cache is created which
requires a disk store, a warning will be issued and will
automatically be used. diskStore has only one attribute – “path”. It is the
path to the directory where .data and .index files will be created. If the
path is one of the following Java System Property it is replaced by its value
in the running VM. For backward compatibility these are not specified without
being enclosed in the ${token} replacement syntax. The following properties
are translated: * user.home – User’s home directory * user.dir – User’s
current working directory * – Default temp file path * – A system property you would normally specify on the
command line e.g. java …
Subdirectories can be specified below the property e.g.
path=”” />

Mandatory Default Cache configuration. These settings will be applied to
caches created programmtically using CacheManager.add(String cacheName). The
defaultCache has an implicit name “default” which is a reserved cache name.

memoryStoreEvictionPolicy=”LRU” />

Storage Location are specified by hard coading paths.

Legal values for the path attibute are legal file system paths.

E.g., for Unix: /home/application/cache

The following system properties are also legal, in which case they are translated:
user.home – User’s home directory
user.dir – User’s current working directory – Default temp file path – A system property

Subdirectories can be specified below the system property, for example:

becomes, on a Unix system:


org.hibernate.HibernateException: No Session found for current thread

I was integrating the Spring and Hibernate on a web application. While do so, I end up with the hibernate exception as follows,

org.hibernate.HibernateException: No Session found for current thread


First we need to understand that the getCurrentSession() only makes sense inside a scope of transaction. We need to declare an appropriate transaction manager, demarcate boundaries of transaction and perform data access inside it. For example, as follows:

<tx:annotation-driven transaction-manager="hibernateTransactionManager"></tx:annotation-driven>

<bean class="org.springframework.orm.hibernate4.HibernateTransactionManager" id="hibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>

<bean class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<property name="hibernateProperties">
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="">${} </prop>

<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="${database.driver}"></property>
<property name="url" value="${database.url}"></property>
<property name="username" value="${database.user}"></property>
<property name="password" value="${database.password}"></property>

At the service and DAO classes, the getSession() method only makes sense inside a scope of transaction, If you are trying to get sessionFactory.getCurrentSession() without defining your class in transactional scope then you will get above exception because getCurrentSession() can be use only in transactional scope. Please make your class transaction using @Transactional annnotation

@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class EmployeeServiceImpl implements EmployeeService {
private EmployeeDao employeeDao;

@Transactional(readOnly = false)
public List listEmployees() {
return employeeDao.listEmployees();

And from my DAO class

public List listEmployees() {
try {
return (List) sessionFactory.getCurrentSession().createCriteria(Employee.class).list();
}catch(Exception e) {
return null;

only looks for @Transactional on beans in the same application context it is defined in. This means that, if you put in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.

The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: [31] in the generated java file: [H:\eclipseWorkspace\J2EEspace\GlossaryPortal\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Spring3HibernateApp\org\apache\jsp\WEB_002dINF\views\]
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory


The below line from the generated java file causing the issue from _jspInit() method

_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();

Previous to this exception, I was facing the below exception

java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config

To resolve this, I have downloaded the following JAR files from the web and placed it in /WEB_INF/lib folder

1) jsp-api-2.0.jar
2) jstl-1.2.jar

But you know, the jsp-api-2.0.jar is now lead to the exception “The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory”.


We should refer the target runtime in our project, not copy some libraries of an arbitrary servletcontainer make/version into our project. It would make our project incompatible with servletcontainers of a different make and/or version.

As simple, if you are using Tomcat 7 as server, then refer the jsp-api.jar from your Tomcat home directory’s lib folder. Don’t arbitrarily download some container version’s jsp=api file.

The project jar files should compatible with your servlet containers, which is the Tomcat Server that you are using as the Target Runtime.


You need to reference a server runtime in your project.

In Eclipse:

1) Choose “Project | Properties | Java Build Path | Libraries Tab”
2) Click “Add Library | Server Runtime | Apache Tomcat 7”
3) Click OK.
4) Clean your project, and build it again (“Project | Clean”, then “Project | Build All”)

That should do it!

Happy Learning 🙂

java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.locatorsUpdateCopy()Z

java.lang.AbstractMethodError: oracle.jdbc.driver.OracleDatabaseMetaData.locatorsUpdateCopy()Z
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$ Source)
org.apache.tomcat.util.threads.TaskThread$ Source)


Switching to Oracle 10g jdbc driver solved the problem immediately, without any configuration change requirements.

Download link:

Remember that Oracle recommends you to use 10 series drivers even if you are connecting to a 8 or 9 series database server!

Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver

I am trying to connection my java web application to the Oracle9i database.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/config/sdnext-servlet.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]


Make sure you have the ojdbc14.jar in your run time classpath.

Download the same from

Happy Learning 🙂