Java Reference
In-Depth Information
What is Maven?
Maven's a build tool provided by the Apache foundation. To use it, download it from . On ce downloaded, you can simply unzip it and add the bin directory your
system's PATH variable. Maven projects rely on convention over configuration. If you examine the source
for this chapter, you'll see the projects are all uniformly structured: src/main/java for Java class files,
src/main/resources for anything that should be on the CLASSPATH at the root of the jar. At the root of
these projects is a pom.xml file, which describes the projects information, including dependencies and
plugins. The dependency information is used to download the required .jar s as you compile the project. It
creates a repository in your home directory (usually, ~/.m2/repository/ ) where all jars are cached and
used for subsequent builds. To compile a project, on the command line issue:
mvn install
Maven doesn't require you to explicitly tell it how to compile or jar source code. If there's java code in the
src/main/java folder, it'll automatically compile it and deposit the resulting artifact (a .jar ) in a target
folder adjacent to the pom.xml file. All major IDE's (Eclipse, IntelliJ IDEA, and Netbeans) support opening
projects and configuring the projects using Maven's pom.xml files. For Eclipse, you'll need the m2eclipse
plug-in. The other two IDEs provide native support. The resulting project will already have all the correct
jars on the classpath so you can begin editing and working with the code right away.
Maven builds follow a life cycle with phases. You can attach custom behavior to these phases (in much the
same way you might listen with a PhaseListener in JSF's request/response processing stack). In the
examples in this chapter, we use a Maven plug-in for building OSGi bundles.
The configuration of the Maven plug-in is simple. The plug-in wraps the bnd tool. The bnd tool
dynamically interrogates classes for their imports and generates OSGi-compliant entries. We repeat it
here mainly for illustrative purposes. For fully working code, see the source code for this topic. Note that
the plug-in produces OSGi-compliant bundles that work in any container. To read more on the plug-in
itself, see: .
helloworld.service.Activator </Bundle-Activator>
Search WWH ::

Custom Search