Archive

Archive for February, 2010

Reading property file in java

February 26, 2010 Leave a comment

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DBProperties {

private static final Log log = LogFactory.getLog(DBProperties.class);
private static final String fileName = “database.properties”;
private static Properties properties;
private static DBProperties instance = null;

private DBProperties() {
properties = new Properties();
try {
InputStream is = getClass().getClassLoader().getResourceAsStream(fileName);
properties.load(is);
} catch (IOException ioe) {
log.error(“Exception occurred while reading the ” + fileName + “file. ” + ioe.getMessage());
}
}

public static DBProperties getInstance() {
log.info(“GetInstance method of DBProperties class”);
if (null == instance) {
instance = new DBProperties();
}
return instance;
}

public String getProperty(String propertyName) {
return properties.getProperty(propertyName);
}
}

Categories: Java

Difference between JPA and hibernate

February 25, 2010 Leave a comment

Java Persistence API (JPA) is a standardized API for persistence in Java.

Hibernate is an implementation of JPA, as well as OpenJPA is another JPA implementation. Each implementation has specific features to extend the JPA functionalities.

JPA is a spec and not an implementation, so if you choose JPA, you still have to pick an implementation. You can pick Hibernate, Toplink, and any other ORM that implements JPA.

-Ram

Categories: Uncategorized

‘xcopy’ is not recognized as an internal or external command

February 22, 2010 Leave a comment

System32 folder might be missing from the PATH environmental variable. Please place this folder in the system path variable.

My Computer -> properties -> advanced ->Environment Variable

Now open a new window and then execute the command.

-Ram

Categories: Uncategorized

Charts in JSF

February 9, 2010 Leave a comment
Categories: JSF

Difference between javac and JIT

February 5, 2010 Leave a comment

Java compiler compiles source files (.java) to bytecode files (.class). Sun gives a free java compiler which is invoked with the ‘javac’ command.

A java interpreter is usually referred to as the Java Virtual Machine (or JVM). It reads and executes the bytecodes in the .class files.  Sun also supplies a free version of the JVM which is invoked with the ‘java’ command.

Where we get confusing is when people talk about a Just-In-Time compiler (or JIT compiler). This is actually part of a JVM. Its purpose is to take the generic (i.e. cross-platform) bytecodes and compile them into more machine-specific instructions (allowing the program to run significantly faster). Even though it is referred to as a JIT ‘compiler’, it is part of the Virtual Machine.

Now, this is what every JVM is facing: should it further translate those byte codes (using that JIT compiler) or should it interpret (or execute) these things itself? JIT compilation is just what it says: just in time compilation. Facing the choice of interpreting those byte codes itself (being slow) or compiling it into real machine code (by activating the JIT compiler) first and then let the real processor do the job, so the real machine code could get executed (or interpreted) by the real CPU is quite a choice to make.

-Ram

Categories: Uncategorized

antiJARLocking attribute set to true in the context xml

February 4, 2010 Leave a comment

If the antiJARLocking attribute is set to true in the context xml, the files contained in the jars will get loaded in the work\_\loader folder of tomcat and if the antiJARLocking attribute is not set to true then the loader folder will not be cretaed in work\_\ folder and also  the files(properties …etc) will be referred from the appropriate jar only.

It is good not to set the antiJARLocking attribute to true in the production environment.

-Ram

Categories: Uncategorized Tags:

SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent

February 4, 2010 Leave a comment

I was using JSF and trying to refresh data automatically using ajax4jsf.

Scenario & Problem :

1. Server is started and the dashboard.seam page is viewed.
2. Now stop the server and do not close the browser…
3. Now restart the server,  following error is getting displayed on the server console.

SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent
Feb 4, 2010 12:07:37 PM org.jboss.seam.web.ExceptionFilter doFilter
WARNING: handling uncaught exception
javax.servlet.ServletException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)

Caused by: javax.faces.application.ViewExpiredException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)

Feb 4, 2010 12:07:37 PM org.jboss.seam.web.ExceptionFilter doFilter
WARNING: exception root cause
javax.faces.application.ViewExpiredException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)

Feb 4, 2010 12:07:37 PM org.ajax4jsf.webapp.BaseXMLFilter doXmlFilter
SEVERE: Exception in the filter chain
javax.servlet.ServletException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.

Solution :

1. Once the server is stopped,  the page that is trying to get the fresh data should also be closed. Otherwise the page will try to get the data and will throw the above error will occur.
2. Once the server is started, now refresh the previously opened page.

Regards,

Ram

Categories: Jboss Seam, JSF