Recent Notes

Displaying keyword search results 1 - 7
Created by Fang on September 07, 2009 20:44:15    Last update: November 03, 2011 14:43:19
Step 1: Repackage a web app as EAR A Java EE application is a multimodule Maven project. At the very least you'll need to package a WAR and an EAR. To get started, I'll simply re-package the simple webapp as an EAR. Create a directory named javaee-app Copy the webapp from here to javaee-app . Rename struts1app to webapp . Create pom.xml under javaee-app : <project> <modelVersion>4.0.0</modelVersion>... Create a directory named ear under javaee-app . Create pom.xml under ear : <project> <modelVersion>4.0.0</modelVersion>... Modify pom.xml in the webapp directory so that it looks like this: <project> <modelVersion>4.0.0</modelVersion> ... Build with " mvn package " in the javaee-app directory. You can see that ear-1.0.ear is successfully generated in javaee-app/ear/target . Maven successfully resolves dependencies between the sub-projects....
Created by freyo on September 07, 2011 16:46:14    Last update: September 07, 2011 19:23:00
The Android unit test framework is based on JUnit 3 , not JUnit 4. Test cases have to extend junit.framework.TestCase or a subclass (such as android.test.InstrumentationTestCase ). Tests are identified by public methods whose name starts with test , not methods annotated with @Test (as in JUnit 4). An Android test suite is packaged as an APK, just like the application being tested. To create a test package, first you need to identify the application package it is testing. Google suggests to put the test package source in a directory named tests/ alongside the src/ directory of the main application. At runtime, Android instrumentation loads both the test package and the application under test into the same process. Therefore, the tests can invoke methods on...
Created by Dr. Xi on April 26, 2011 20:12:01    Last update: April 28, 2011 15:28:12
An XML schema is a definition of XML files, in XML. It plays the same role as old-time DTDs. Overall, an XML schema file looks like this: <schema attributeFormDefault = (qualified | u... The attribute meanings: targetNamespace : The name space targeted by the current schema definition. It can be any URI. id and version : For user convenience, the W3C spec defines no semantics for them. xml:lang : Natural language identifier defined by RFC 3306 . attributeFormDefault and elementFormDefault : Set default values for the form attribute for attribute and element declarations. blockDefault and finalDefault : Set default values for the block and final attributes for attribute and element declarations. The W3C defined some built-in datatypes . Examples of primitive datatypes are: string ,...
Created by Dr. Xi on March 02, 2011 11:39:18    Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code: import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by nogeek on November 11, 2010 00:26:08    Last update: November 11, 2010 00:29:43
This one is even more weird: it worked on Windows but failed on Linux, using default tools JDK1.6.0_20 on both. The exception thrown was: java.lang.RuntimeException: Invalid conversion fro... And the stack trace: java.lang.RuntimeException: Invalid conversion fro... This was the XSL used: <?xml version="1.0" encoding="ISO-8859-1"?> <xs... The problem was , DateUtil.java had two getDate methods, one taking long parameter, the other taking a String parameter. And Java's XSLT get confused about which one to use: import java.util.Date; import java.text.SimpleD...
Created by Dr. Xi on July 29, 2010 18:46:57    Last update: July 29, 2010 18:48:15
This is an example of using java.beans.XMLEncoder and java.beans.XMLDecoder to serialize/deserialize Java objects to XML. Java code TestXMLEncoder.java: import java.io.*; import java.beans.XMLEncoder;... SimpleBean.java: public class SimpleBean { private String na... CompositeBean.java: public class CompositeBean { private Simple... NotABean.java: public class NotABean { private String name... Test Output By default, only Java beans can be serialized using XMLEncoder . Exception occurs when you try to deserialize an object which is not a Java bean. Errors actually occur when you try to serialize, but they are ignored. As a result, an XML file is generated by the serialization but the file is useless! Console output: C:\>java TestXMLEncoder Testing simple bean ... simplebean.xml: <?xml version="1.0" encoding="UTF-8"?> <java v... compositebean.xml: <?xml version="1.0" encoding="UTF-8"?> <java v... nodefault.xml: <?xml version="1.0" encoding="UTF-8"?> <java v......
Created by Dr. Xi on October 23, 2008 03:54:04    Last update: October 23, 2008 03:57:44
Add validator plugin in struts-config.xml <struts-config> . . . ... Set validate="true" on action form <struts-config> <!-- ========== Form Bean De... Add validation rules in validation.xml <?xml version='1.0' encoding='windows-1252'?> <... If you override validate , make sure super.validate is called. package com.example; import javax.servlet.h... Read the documentation: http://struts.apache.org/1.2.4/userGuide/dev_validator.html