Tuesday, June 5, 2007

Weblogic etc..

Pre Compile Java Server Pages (JSP) using ANT :



<java classname="weblogic.jspc" fork="true" failonerror="true" dir="${war.home}">
<jvmarg value="-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0"/>
<jvmarg value="-Dweblogic.jsp.windows.caseSensitive=true"/>
<classpath>
<pathelement path="${weblogic-related.jars}"/>
<pathelement path="${application-related.jars}"/>
<pathelement path="${java.class.path}"/>
</classpath>
<arg line="-depend -compileAll -keepgenerated -d WEB-INF/classes ."/>
</java>





Weblogic.9.2 and JDK 1.5.0_011.
Weblogic 9.2 comes with JDK 1.5.0.04 version. If you need to point to JDK version 1.5.0_011, then you need to use a parameter:
-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0

Make sure the domain is using the right JDK version. Make use of this parameter in startWeblogic.cmd/.sh files. Also can be used when running Ant tasks.



Java Utils

Some of my past works include the use of various JDK API:


Adler32 API Usage:
What is this API used for ?
Checksum is the answer. To compute the Adler-32 checksum of a data stream.
We need this in order to know if a data stream has changed in time.
Set the checksum and then read the file again to see if the checksum has changed. if so , meaning file has changed.
Check the code here.


String fileContents = null;
long adlerCheckSumValue = 0l;
// read the file contents into fileContents as a string.
Adler32 adlerCheckSum = new Adler32();
checkSum.update(fileContents.getBytes());
adlerCheckSumValue = adlerCheckSum .getValue();

OR

//get the check sum value from the given input stream.

CheckedInputStream cis = new CheckedInputStream(inputStream, adlerCheckSum );
while (cis.read() != -1) {
//Do nothing here
}

adlerCheckSumValue = adlerCheckSum .getValue();







Simple log4j logging configuration for simple utilities:
The Pattern logs this way :

[ INFO ]:: 2007-06-26 17:42:42,001:: com.xxx.xxx.xx.XXXXX.main(XXXXX.java:147):: This is the log message...


String pattern = "[ %p ]";
pattern += ":: %d";
pattern += ":: %l";
pattern += ":: %m %n";

PatternLayout layout = new PatternLayout(pattern);
FileAppender appender = new FileAppender(layout, filePath);
Logger logger = Logger.getLogger(theClass);
logger.addAppender(appender);

filepath is the absolute path with log file name.
theClass is the class object.