Recent Notes
Displaying keyword search results 1 - 10
Created by Fang on January 10, 2010 00:19:30
Last update: January 31, 2012 16:28:42
Maven is a powerful yet complex tool. When I started learning Maven, the first obstacle was, of course, its complexity. The second, was the lack of documentation that can get me off the ground quickly. This tutorial is an attempt to create a pragmatic guide that aims to get you familiar with Maven in the quickest way possible. The main theme is to get you on some hands on experience to start out and lead you through the creation of a simple Java EE project as quickly as possible. Instead of trying to give you a good read, I try to get you on the journey right away. The topics are roughly ordered by the logical sequence but you can jump around in any way...
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 Fang on October 28, 2011 14:49:53
Last update: October 28, 2011 14:52:19
Facelet templates can be nested, for example, a page can use a template which inherits from another template. To demonstrate this, let's start from the simple example and make these additions:
Add a place holder for CSS style sheets in WEB-INF/templates/default.xhtml :
<h:head>
<title>Facelets Template Demo</tit...
Add a derivative template ( WEB-INF/templates/default-style.xhtml ) which provides CSS:
<?xml version="1.0" encoding="UTF-8"?>
<ui:comp...
Add a page that uses the styled template ( home-style.xhtml ):
<?xml version="1.0" encoding="UTF-8"?>
<ui:comp...
The only difference between this file and home.xhtml is the template being used.
Compare the display of the pages home.xhtml and home-style.xhtml .
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 alfa on July 01, 2011 13:16:12
Last update: July 01, 2011 13:16:12
This is a simple doclet that prints all public methods and their parameter names and types.
Code
import com.sun.javadoc.*;
public class List...
Compile
javac -cp $JAVA_HOME/lib/tools.jar:. ListMethodsDo...
Use
javadoc -doclet ListMethodsDoclet -sourcepath /pat...
Created by Dr. Xi on June 13, 2011 15:05:27
Last update: June 13, 2011 15:10:24
When you pass parameters from shell to Java, the list arguments may be messed up if there are spaces in the values.
Start with a simple Java test class:
public class EchoParams {
public static voi...
Tests:
$ java EchoParams a b c
Arg: a
Arg: b
Arg...
Now wrap the command in a shell script ( echoparams.sh ):
#!/bin/sh
java EchoParams $*
Tests:
$ ./echoparams.sh a b c
Arg: a
Arg: b
Arg...
The quotes had no effect on the parameters list.
Changing $* to $@ produces the same results.
The correct way to quote the args list is: "$@"
#!/bin/sh
java EchoParams "$@"
Test:
$ ./echoparams.sh a b "c d" "1 2 3 4 5"
Arg: a
...
Created by alfa on June 03, 2011 09:41:03
Last update: June 03, 2011 09:41:03
Dynamic proxy can be used to eliminate the need to stub out unused interface methods. This is an example for a simple SAX content handler for XML parsing.
The org.xml.sax.ContentHandler interface requires 11 methods be implemented but we only need three:
import java.io.IOException;
import java.util.Ar...
With a dynamic proxy, we don't need the empty blocks for the unused methods:
import java.io.IOException;
import java.util.Ar...
Equivalently (with anonymous inner class):
import java.io.IOException;
import java.util.Ar...
demo.xml :
<breakfast-menu>
<food>
<name>Belgian W...
Created by Dr. Xi on February 28, 2011 15:39:08
Last update: February 28, 2011 15:39:08
For simple projects, archetype:generate seemed too heavy for me, but creating the standard Maven file structure by hand is such a chore. So I created this simple script to ease the pain:
#!/bin/sh
if [ $# -lt 4 ]; then
echo "Us...
Example usage:
./initmvn.sh myProject theGroupId theArtifactId co...
Created by Dr. Xi on October 26, 2010 04:47:37
Last update: January 11, 2011 20:00:36
The code presented here is a simple implementation of a tab set. It is used to demo how a tab set could be implemented. The code is stand alone and does not depend on any JavaScript libraries. Multiple tab sets within the same page is supported.
The HTML markup is fairly simple:
Tabs sets are contained within a DIV element with class name "tabsContainer".
Define a UL list for the tabs.
Follow the UL list with equal number of DIVs for the tab contents.
The Nifty Corners Cube technique is used to draw the rounded corners (original form, not the enhanced JavaScript form).
HTML, CSS and JavaScript:
<!doctype html>
<html>
<head>
<style typ...
Created by James on June 30, 2010 19:04:45
Last update: July 03, 2010 21:24:33
Technically, file upload cannot be handled by Ajax, because XMLHttpRequest (XHR) does not handle file inputs. All techniques not using Flash rely on an invisible iframe as the upload form submit target. JavaScript then grabs the response content from the iframe and present it, giving the same illusion as Ajax. webtoolkit AIM The technique by webtoolkit is very simple. It involves 3 simple steps: include the AIM script, implement the start/finish JavaScript functions, and add an onsubmit handler to the normal file upload form. The hooked up form looks like:
<head> <script type="text/javascript" src="webt... The AIM script is also quite simple: /** * * AJAX IFRAME METHOD (AIM) * http... The above code only supports HTML responses. In order to support JSON responses, the above...