31 dic 2010

Center DIV/Container/Layer IE : flumpCakes

This is a demo to show how to center a DIV in the center of the screen from Internet Explorer 4 and up. Including all modern browsers too.
The trick is to add text-align: center; to the body selector, then add the usual margin: 0 auto; to the container selector which you want centered. Apply text-align: left; on the container to counter the center align for body.
View this pages source code to see how it's done

28 dic 2010

Message Broker help: XML standalone

XML standalone

El elemento XML standalone define la existencia de una DTD definida externamente.
Es un elemento de valor y almacena los datos correspondientes al valor de la serie autónoma de la declaración. Es siempre hijo del elemento XmlDecl. Los valores válidos para el elemento autónomo son yes y no. An example is shown below:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE s1 PUBLIC "http://www.ibm.com/example.dtd" 
"example.dtd" >
<s1>.........</s1>
Un valor de no indica que este documento XML no es autónomo y depende de una DTD definida externamente. Un valor de yes indica que el documento XML es un documento independiente. Sin embargo, dado que el release actual de WebSphere Message Broker no resuelve las DTD definidas externamente, el valor de standalone (autónomo) no es relevante y se ignora.

15 dic 2010

Maven - Frequently Asked Technical Questions

  1. How do I prevent "[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!"
  2. How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope!
  3. How do I list available plugins?
  4. How do I determine what version of a plugin I am using?
  5. How can I use Ant tasks in a Maven build?
  6. How can I use Maven features in an Ant build?
  7. How do I set up Maven so it will compile with a target and source JVM of my choice?
  8. Is it possible to create my own directory structure?
  9. Where is the source code? I couldn't seem to find a link anywhere on the Maven2 site.
  10. Maven can't seem to download the dependencies. Is my installation correct?
  11. I have a jar that I want to put into my local repository. How can I copy it in?
  12. How do I unsubscribe from Maven mailing lists?
  13. How do I skip the tests?
  14. How can I run a single unit test?
  15. Handle special characters in site
  16. How do I include tools.jar in my dependencies?
  17. Maven compiles my test classes but doesn't run them?
  18. Where are Maven SNAPSHOT artifacts?
  19. Where are the Maven XSD schemas?
  20. Maven doesn't work, how do I get help?
  21. How to produce execution debug output or error messages?
  22. What is a Mojo?
  23. How to find dependencies on public Maven repositories?

An introduction to Maven 2 - JavaWorld

Maven is a popular open source build tool for enterprise Java projects, designed to take much of the hard work out of the build process. Maven uses a declarative approach, where the project structure and contents are described, rather then the task-based approach used in Ant or in traditional make files, for example. This helps enforce company-wide development standards and reduces the time needed to write and maintain build scripts.
The declarative, lifecycle-based approach used by Maven 1 is, for many, a radical departure from more traditional build techniques, and Maven 2 goes even further in this regard. In this article, I go through some of the basic principals behind Maven 2 and then step through a working example. Let's start by reviewing the fundamentals of Maven 2.

The project object model

The heart of a Maven 2 project is the project object model (or POM for short). It contains a detailed description of your project, including information about versioning and configuration management, dependencies, application and testing resources, team members and structure, and much more. The POM takes the form of an XML file (pom.xml), which is placed in your project home directory. A simple pom.xml file is shown here:
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
 http://maven.apache.org/maven-v4_0_0.xsd">
  4.0.0
  com.javaworld.hotels
  HotelDatabase
  war
  1.0-SNAPSHOT
  Maven Quick Start Archetype
  http://maven.apache.org
  
     
        junit
        junit
        3.8.1
        test
     
  


The Maven 2 directory structure

Much of Maven's power comes from the standard practices it encourages. A developer who has previously worked on a Maven project will immediately feel familiar with the structure and organization of a new one. Time need not be wasted reinventing directory structures, conventions, and customized Ant build scripts for each project. Although you can override any particular directory location for your own specific ends, you really should respect the standard Maven 2 directory structure as much as possible, for several reasons:
  • It makes your POM file smaller and simpler
  • It makes the project easier to understand and makes life easier for the poor guy who must maintain the project when you leave
  • It makes it easier to integrate plug-ins
The standard Maven 2 directory structure is illustrated in Figure 1. In the project home directory goes the POM (pom.xml) and two subdirectories: src for all source code and target for generated artifacts.

Figure 1. The standard Maven 2 directory layout
The src directory has a number of subdirectories, each of which has a clearly defined purpose:
  • src/main/java: Your Java source code goes here (strangely enough!)
  • src/main/resources: Other resources your application needs
  • src/main/filters: Resource filters, in the form of properties files, which may be used to define variables only known at runtime
  • src/main/config: Configuration files
  • src/main/webapp: The Web application directory for a WAR project
  • src/test/java: Unit tests
  • src/test/resources: Resources to be used for unit tests, but will not be deployed
  • src/test/filters: Resources filters to be used for unit tests, but will not be deployed
  • src/site: Files used to generate the Maven project Website

Project lifecycles

Project lifecycles are central to Maven 2. Most developers are familiar with the notion of build phases such as compile, test, and deploy. Ant has targets with names like those. In Maven 1, corresponding plug-ins are called directly. To compile Java source code, for instance, the java plug-in is used:
 $maven java:compile


In Maven 2, this notion is standardized into a set of well-known and well-defined lifecycle phases (see Figure 2). Instead of invoking plug-ins, the Maven 2 developer invokes a lifecycle phase: $mvn compile.

Figure 2. Maven 2 lifecycle phases
Some of the more useful Maven 2 lifecycle phases are the following:
  • generate-sources: Generates any extra source code needed for the application, which is generally accomplished using the appropriate plug-ins
  • compile: Compiles the project source code
  • test-compile: Compiles the project unit tests
  • test: Runs the unit tests (typically using JUnit) in the src/test directory
  • package: Packages the compiled code in its distributable format (JAR, WAR, etc.)
  • integration-test: Processes and deploys the package if necessary into an environment where integration tests can be run
  • install: Installs the package into the local repository for use as a dependency in other projects on your local machine
  • deploy: Done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects
Many other lifecycle phases are available. See Resources for more details.
These phases illustrate the benefits of the recommended practices encouraged by Maven 2: once a developer is familiar with the main Maven 2 lifecycle phases, he should feel at ease with the lifecycle phases of any Maven project.
The lifecycle phase invokes the plug-ins it needs to do the job. Invoking a lifecycle phase automatically invokes any previous lifecycle phases as well. Since the lifecycle phases are limited in number, easy to understand, and well organized, becoming familiar with the lifecycle of a new Maven 2 project is easy.

Transitive dependencies

One of the highlights of Maven 2 is transitive dependency management. If you have ever used a tool like urpmi on a Linux box, you'll know what transitive dependencies are. With Maven 1, you have to declare each and every JAR that will be needed, directly or indirectly, by your application. For example, can you list the JARs needed by a Hibernate application? With Maven 2, you don't have to. You just tell Maven which libraries you need, and Maven will take care of the libraries that your libraries need (and so on).
Suppose you want to use Hibernate in your project. You would simply add a new dependency to the dependencies section in pom.xml, as follows:
  
     hibernate
     hibernate
     3.0.3
     compile
  


And that's it! You don't have to hunt around to know in which other JARs (and in which versions) you need to run Hibernate 3.0.3; Maven will do it for you!
The XML structure for dependencies in Maven 2 is similar to the one used in Maven 1. The main difference is the scope tag, which is explained in the following section.

Dependency scopes

In a real-world enterprise application, you may not need to include all the dependencies in the deployed application. Some JARs are needed only for unit testing, while others will be provided at runtime by the application server. Using a technique called dependency scoping, Maven 2 lets you use certain JARs only when you really need them and excludes them from the classpath when you don't.