Wednesday, July 1, 2009

How to tail Tomcat in Linux

In TOMCAT_HOME directory:
tail -f logs/catalina.out

Sunday, May 17, 2009

Java: How to Convert Array to List

Object[] array = new Object[]{"12","23","34"};
java.util.List list = Arrays.asList(array);

Thursday, May 14, 2009

Start Tomcat At 128m

The easiest way to start Tomcat at 128m is to set CATALINA_OPTS as an environment variable.

CATALINA_OPTS
-Xms128m -Xmx256m

How To Get A Value From Your Properties File

Properties properties = new Properties();

try {
ClassLoader classLoader = Thread.currentThread()
.getContextClassLoader();
InputStream is = classLoader
.getResourceAsStream("file.properties");
if (is != null) {
properties.load(is);
value = properties.getProperty("key");
is.close();
}
is = null;
}

catch (Exception e) {
e.printStackTrace();
}

Wednesday, May 13, 2009

How To Attach AsyncAppender To Your Other Appenders

In your log4j.xml, define the AsyncAppender and reference the other appenders that you want to attach to it.

appender name="ASYNC" class="org.apache.log4j.AsyncAppender"
appender-ref ref="STDOUT"
appender


appender name=STDOUT" class="org.apache.log4j.ConsoleAppender"
layout class="org.apache.log4j.PatternLayout"
param name="ConversionPattern" value="%d{HH:mm:ss:SSS} %-5p %C:%L %M() %m%n"
layout
appender

Then define ASYNC as your root logger.

root
appender-ref ref="ASYNC"
root