Maven example

R

Roedy Green

Would anyone be willing to submit commented Maven files for a real
project to be published in the Java glossary Maven entry to give
people an idea of how to use Maven and what it can do?
--
Roedy Green Canadian Mind Products
http://mindprod.com

There is a certain cosmic justice in the bankruptcy of General Motors. People at every level of the economic spectrum who for
economic motives helped GM pummel the environment with deliberately inefficient automobiles are being punished both severely and economically.
 
O

Owen Jacobson

Would anyone be willing to submit commented Maven files for a real
project to be published in the Java glossary Maven entry to give
people an idea of how to use Maven and what it can do?

I use Maven for all of my Java development these days, most of which is
available under MIT (or LGPL) from http://alchemy.grimoire.ca/hg/ .
Unfortunately, there aren't any EE examples there; that's one of the
places Maven really shows its value, but there are single-module JAR
projects (mainspring, event-dispatching) and multi-module JAR projects
(jnoise, maven-utils).

Feel free to pick over it and see if there's anything useful.

-o
 
O

Owen Jacobson

Thanks. The pom files don't seem to contain much low level
information. I gather they have a standard way of handling all the
low level details.

Indeed they do. The <packaging> element, near the top, is enough to
tell maven *how* to build things, in most cases:
<packaging>jar</packaging, for example, causes src/main/java to be
compiled, src/main/resources to be copied (and optionally filtered
through a token-replacement layer), src/test/java to be compiled and
run as test cases, then the resulting classes and files from src/main
used to build a JAR. There are built-in packaging types for JARs, WARs,
EARs, EJB-JARs, RARs and some maven infrastructure types like pom. New
packaging types (with associated "standard" build procedures) can be
implemented as plugins - there are, for example, plugins for JBoss SAR
files, Flex applications and libraries, and a bunch of other things.

If you need to specify things about *how* to build something, you can
add new plugins to the build (not shown in the example, but I can cook
one up) or reconfigure the standard plugins to behave differently.
There's also an inheritance model, where projects can inherit settings,
including

Most of the information in pom.xml is actually not related to building
the project at all: it's metadata about the project. I've annotated one
of my single-module POMs (below) to give a better idea of how to use it
in a simple project, and a better idea of what's optional versus
mandatory. A lot of the things in my own projects' POMs are required
for projects being uploaded to central (http://repo1.maven.org/maven2/)
but not for in-house projects -- license metadata, for example, is less
relevant if code isn't being released outside of an organization.

For a really simple JAR project with no dependencies, and that doesn't
need to meet anyone's metadata strictness requirements, this is a
complete POM:

--- minimal-pom.xml ---
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>

<groupId>ca.grimoire.examples</groupId>
<artifactId>tiny-pom</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>

<name>A very short example POM</name>

A nice start. I'm happy to contribute, but I've learned I do a better
job of explaining things when people ask questions than when I just
ad-lib for an hour.

-o

--- Annotated pom.xml, adapted from
http://alchemy.grimoire.ca/hg/mainspring-daemon/file/2465413158e6/pom.xml
---
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
<modelVersion>4.0.0</modelVersion>

<!-- A reference to a POM to inherit settings from. (Optional, useful
in multiple-JAR projects or for inheriting organization-wide
defaults.)-->
<parent>
<artifactId>alchemy-parent</artifactId>
<groupId>ca.grimoire</groupId>
<version>4</version>
</parent>

<!-- The project identifier consists of a groupId, which may be shared
between projects, and an artifactId, which must be unique within
a groupId. -->
<groupId>ca.grimoire</groupId>
<artifactId>mainspring-daemon</artifactId>
<!-- The type of project being built. Maven uses this to decide how to
perform the build itself. -->
<packaging>jar</packaging>
<!-- The project's version. The suffix -SNAPSHOT marks this build as a
development build, not intended for use outside the project. -->
<version>1.0-SNAPSHOT</version>

<!-- Human-readable, decorative name for the project. -->
<name>Mainspring Uncontainer for Daemons</name>
<!-- The project's homepage. (Optional.) -->
<url>http://alchemy.grimoire.ca/m2/sites/ca.grimoire/mainspring-daemon</url>

<!-- A human-readable description of the project. (Optional.) -->
<description>
Mainspring provides a way to bootstrap Spring contexts from JARs
without a web or application container. This version uses
commons-daemon to bootstrap, rather than main().
</description>

<!-- A list of developers and contributors involved in the project.
(Optional.) -->
<developers>
<developer>
<id>owen.jacobson</id>
<name>Owen Jacobson</name>
<email>[email protected]</email>
<timezone>-5</timezone>
</developer>
</developers>

<!-- The license or licenses the project is being distributed under.
(Optional.) -->
<licenses>
<license>
<name>MIT</name>
<url>http://alchemy.grimoire.ca/licenses/MIT-LICENSE</url>
</license>
</licenses>

<!-- Version control information. (Optional, but recommended.) -->
<scm>
<!-- For users and third-party developers without commit access. -->
<connection>
scm:hg:http://alchemy.grimoire.ca/hg/mainspring-daemon/
</connection>
<!-- For developers with commit access. The developerConnection URL
is also used by certain plugins, including the 'release'
plugin, to track automated changes to the project. -->
<developerConnection>
scm:hg:http://alchemy.grimoire.ca/hg/mainspring-daemon/
</developerConnection>
</scm>

<!-- A link to the project's bug tracker. (Optional.) -->
<issueManagement>
<system>JIRA</system>
<url>http://alchemy.grimoire.ca/jira/browse/MS</url>
</issueManagement>

<!-- A link to the project's build server. (Optional.) -->
<ciManagement>
<system>Hudson</system>
<url>http://alchemy.grimoire.ca/hudson/</url>
</ciManagement>

<!-- The projects needed to build or run this project. (Semi-optional:
if your project has no dependencies, you can omit this.) -->
<dependencies>
<!-- A normal dependency, needed to build and run the project. -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.6</version>
</dependency>

<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.1</version>
</dependency>

<!-- A dependency that's only needed during testing. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<!-- Controls reports that appear if you're using the maven website
generation tools. (Optional.) -->
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>

<configuration>
<links>
<link>http://java.sun.com/javase/6/docs/api</link>
<link>
http://static.springframework.org/spring/docs/2.5.x/api
</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting>

<!-- URLs to upload various build products to. (Optional.) -->
<distributionManagement>
<!-- Where to upload "release" (non-SNAPSHOT) builds. -->
<repository>
<id>alchemy.grimoire.ca</id>
<url>dav:http://alchemy.grimoire.ca/m2/releases/</url>
</repository>
<!-- Where to upload "development" (SNAPSHOT) builds. -->
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>alchemy.grimoire.ca</id>
<url>dav:http://alchemy.grimoire.ca/m2/snapshots/</url>
</snapshotRepository>
<!-- Where to upload the maven generated website. -->
<site>
<id>alchemy.grimoire.ca</id>

<url>dav:http://alchemy.grimoire.ca/m2/sites/ca.grimoire/mainspring-daemon</url>


</site>
</distributionManagement>
</project>
--- EOF ---
 
O

Owen Jacobson

Thanks. The pom files don't seem to contain much low level
information. I gather they have a standard way of handling all the
low level details.

See http://mindprod.com/jgloss/maven.html

Oh - you'll probably want to mention two things:
1. The standard plugin list, which is at
http://maven.apache.org/plugins/index.html

2. mvnrepository, which is a search engine for packages that are in
central, at http://www.mvnrepository.com/

You can, for example, find most of my stuff by searching mvnrepository
for 'ca.grimoire' :)

-o
 
R

Roedy Green

Indeed they do. The <packaging> element, near the top, is enough to
tell maven *how* to build things, in most cases:

thanks. I have incorporated most of what you had to say in the entry.

see http://mindprod.com/jgloss/maven.html

Anyone have some questions or thoughts to improve the entry?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Never discourage anyone... who continually makes progress, no matter how slow.
~ Plato 428 BC died: 348 BC at age: 80
 
R

Roedy Green

Have you thought about turning the glossary into a (probably moderated) wiki?

I looked into it. The problem with Wikis is they have only the most
primitive formatting ability specified with the most disgusting
syntax. I am far too anal to put up with it. My site is quite rigidly
controlled with style sheets and macros. What might work is some sort
of public wiki appendices on each entry or embedded commentary links.
To do that, I need a host that lets me run code on the server. A
friend of mine hosts my site free.

The other problem is I have many enemies. I have even had a fatwa put
on me by right wing radio host. My opinions on gay lib, religion, US
politics, and even Java are unpopular. I would have more problem than
most with attempts to derail the wiki. I think I would need a
registering system, and a way to undo changes made by any disgraced
member.

For people to invest time in a Wiki, they want to be sure the project
will live on, and that their work will not be too severely edited.

Perhaps I could start with soliciting guest entries, where the content
for an entry or part of an entry is controlled by a guest author. They
would submit content by email or blog, and I would look after
formatting and inserting it in the static HTML.

I get quite a bit of feedback on typos and confusing entries, and
requests for links to things. I don't get much contributed content.

The entire website reverts to the public domain on my death. I would
hope the site would live on. Old information can be worse than no
information.

I invite you to take charge of the content of the Maven entry. You are
already credited.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Never discourage anyone... who continually makes progress, no matter how slow.
~ Plato 428 BC died: 348 BC at age: 80
 
M

Michael Justin

Roedy said:
thanks. I have incorporated most of what you had to say in the entry.

see http://mindprod.com/jgloss/maven.html

Anyone have some questions or thoughts to improve the entry?


<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
 
R

Roedy Green

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
--

Could you provide a bit of context on what that your intent for that
snippet was? suggested addition? a query what it means?
--
Roedy Green Canadian Mind Products
http://mindprod.com

Never discourage anyone... who continually makes progress, no matter how slow.
~ Plato 428 BC died: 348 BC at age: 80
 
O

Owen Jacobson

Could you provide a bit of context on what that your intent for that
snippet was? suggested addition? a query what it means?

Heh. Michael raises a good point.

Maven's default compiler compliance level (regardless of JDK) is Java
1.3 (-source 1.3 -target 1.3). The above plugin configuration sets the
compliance level to Java 5 (-source 1.5 -target 1.5). I always forget
to mention it because I have it set that way in my org POM.

Calling back to my annotated example, you can insert the following
after </dependencies> and before <reporting>:

<!-- Build customizations. (Optional.) -->
<build>
<plugins>
<plugin>
<!-- Customize the behaviour of the java compiler plugin. See
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
(Semi-Optional, if you're not using Java 5 features.) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>

<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>

There is an open bug to change the default compliance level to 1.5:
http://jira.codehaus.org/browse/MCOMPILER-80 - there's a
backwards-compatability reason not to change the default, but it's
getting harder and harder to justify.

-o
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top