Maven example

Discussion in 'Java' started by Roedy Green, Jun 2, 2009.

  1. Roedy Green

    Roedy Green Guest

    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.
     
    Roedy Green, Jun 2, 2009
    #1
    1. Advertising

  2. On 2009-06-02 17:24:36 -0400, Roedy Green
    <> said:

    > 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
     
    Owen Jacobson, Jun 3, 2009
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    On Wed, 3 Jun 2009 11:01:14 -0400, Owen Jacobson
    <> wrote, quoted or indirectly quoted someone
    who said :

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


    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
    --
    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
     
    Roedy Green, Jun 3, 2009
    #3
  4. On 2009-06-03 14:07:11 -0400, Roedy Green
    <> said:

    > On Wed, 3 Jun 2009 11:01:14 -0400, Owen Jacobson
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >>
    >> Feel free to pick over it and see if there's anything useful.

    >
    > 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>
    </project>
    --- EOF ---

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


    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>
    <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 ---
     
    Owen Jacobson, Jun 4, 2009
    #4
  5. On 2009-06-03 14:07:11 -0400, Roedy Green
    <> said:

    > On Wed, 3 Jun 2009 11:01:14 -0400, Owen Jacobson
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >>
    >> Feel free to pick over it and see if there's anything useful.

    >
    > 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
     
    Owen Jacobson, Jun 4, 2009
    #5
  6. Roedy Green

    Roedy Green Guest

    On Wed, 3 Jun 2009 20:40:46 -0400, Owen Jacobson
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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
     
    Roedy Green, Jun 4, 2009
    #6
  7. On 2009-06-03 23:25:01 -0400, Roedy Green
    <> said:

    > On Wed, 3 Jun 2009 20:40:46 -0400, Owen Jacobson
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    >> 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?


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

    -o
     
    Owen Jacobson, Jun 4, 2009
    #7
  8. Roedy Green

    Roedy Green Guest

    On Thu, 4 Jun 2009 10:06:03 -0400, Owen Jacobson
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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
     
    Roedy Green, Jun 4, 2009
    #8
  9. Roedy Green wrote:

    > 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>
    --
    Michael Justin
    SCJP, SCJA
    betasoft - Software for Delphiâ„¢ and for the Javaâ„¢ platform
    http://www.mikejustin.com - http://www.betabeans.de
     
    Michael Justin, Jun 7, 2009
    #9
  10. Roedy Green

    Roedy Green Guest

    On Sun, 07 Jun 2009 14:50:07 +0200, Michael Justin
    <> wrote, quoted or indirectly quoted
    someone who said :

    >> 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>
    >--


    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
     
    Roedy Green, Jun 7, 2009
    #10
  11. On 2009-06-07 14:57:25 -0400, Roedy Green
    <> said:

    > On Sun, 07 Jun 2009 14:50:07 +0200, Michael Justin
    > <> wrote, quoted or indirectly quoted
    > someone who said :
    >
    >>> 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>
    >> --

    >
    > 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
     
    Owen Jacobson, Jun 8, 2009
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sherman Haywood Cox II

    Maven and ejbc

    Sherman Haywood Cox II, Jul 25, 2003, in forum: Java
    Replies:
    0
    Views:
    453
    Sherman Haywood Cox II
    Jul 25, 2003
  2. steven

    maven and xdoclet

    steven, Nov 12, 2003, in forum: Java
    Replies:
    1
    Views:
    379
    Bryce (Work)
    Nov 12, 2003
  3. Marko Velic

    XP %HOME% and Maven

    Marko Velic, Jun 10, 2004, in forum: Java
    Replies:
    0
    Views:
    371
    Marko Velic
    Jun 10, 2004
  4. Marcin Cenkier
    Replies:
    1
    Views:
    5,424
    Marcin Cenkier
    Apr 12, 2006
  5. manos
    Replies:
    0
    Views:
    233
    manos
    Oct 6, 2007
Loading...

Share This Page