Child pages
  • Maven Kicking the tyres without changing your project structure

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Assuming your building a framework, for example, the following is an extract from the relevant pom.xml. It specifies where to find your java source files and resources, we can put this in /trunk/pom.xml and then all the child pom.xml files will know we're using Fluffy Bunny Layout. Notice we've also defined the target path for each resource. (See the WOL:Maven Model#class_resource for a definition of targetPath)

Code Block
xmlxml
titlepom.xml
xml
<...>
  <build>
    <sourceDirectory>Sources</sourceDirectory>
    <testSourceDirectory>Tests</testSourceDirectory>
    <resources>
      <resource>
        <targetPath>Resources</targetPath>
        <filtering>false</filtering>
        <directory>Components</directory>
      </resource>
      <resource>
        <targetPath>Resources</targetPath>
        <filtering>false</filtering>
        <directory>Resources</directory>
      </resource>
      <resource>
        <targetPath>WebServerResources</targetPath>
        <filtering>false</filtering>
        <directory>WebServerResources</directory>
      </resource>
    </resources>
    <...>
  </build>
<...>

...

Attachments
uploadfalse
patternsInfo.plist
Code Block
xmlxml
title/frameworks/pom.xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <!-- parent artifact -->
    <parent>
        <artifactId>mywostuff</artifactId>
        <groupId>com</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!-- artifact identity -->
    <artifactId>frameworks</artifactId>
    <groupId>com.mywostuff</groupId>
    <packaging>pom</packaging>

    <!-- framework relevant properties -->
    <properties>
        <!-- NS related properties fills in Info.plist etc-->
        <CFBundleDevelopmentRegion>English</CFBundleDevelopmentRegion>
        <CFBundleGetInfoString></CFBundleGetInfoString>
        <CFBundlePackageType>FMWK</CFBundlePackageType>
        <CFBundleIconFile>WOAfile.icns</CFBundleIconFile>
        <CFBundleInfoDictionaryVersion>6.0</CFBundleInfoDictionaryVersion>
        <CFBundleVersion>5.3.1</CFBundleVersion>
        <Has_WOComponents>true</Has_WOComponents>
        <NSPrincipalClass>${mainclass}</NSPrincipalClass>
        <NSResourcesBundlePath></NSResourcesBundlePath>
    </properties>

    <!-- modules -->
    <modules>
        <module>CustomExtensions</module>
        <module>CustomBusinessLogic</module>
    </modules>

    <!-- specific dependencies (for modules) -->
    <dependencies>
        <dependency>
            <artifactId>ERExtensions</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWOExtensions</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaFoundation</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaJDBCAdaptor</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWebObjects</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaEOControl</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaEOAccess</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWebObjects</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaXML</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
    </dependencies>


    <!-- build config (for modules) -->
    <build>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>tests</testSourceDirectory>
        <resources>
            <!-- relative dir for Info.plist -->
            <resource>
                <targetPath>Resources</targetPath>
                <filtering>true</filtering>
                <directory>../src/main/resources</directory>
            </resource>
            <resource>
                <targetPath>Resources</targetPath>
                <filtering>false</filtering>
                <directory>Components</directory>
            </resource>
            <resource>
                <targetPath>Resources</targetPath>
                <filtering>false</filtering>
                <directory>Resources</directory>
            </resource>
            <resource>
                <targetPath>WebServerResources</targetPath>
                <filtering>false</filtering>
                <directory>WebServerResources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.target}</source>
                    <target>${java.target}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Since our CustomExtensions has no further dependencies, its pom.xml merely specifies its parent and its identity.

Code Block
xmlxml
title/frameworks/CustomBusinessLogic/pom.xml
xml
<?xml version="1.0"?>
<project>
    <!-- parent artifact -->
    <parent>
        <artifactId>frameworks</artifactId>
        <groupId>com.mywostuff</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!-- artifact identity -->
    <artifactId>CustomBusinessLogic</artifactId>
    <groupId>com.mywostuff.frameworks</groupId>
</project>

CustomBusinessLogic has a further dependency on CustomExtensions, so it specifies its parent, its identity, and the dependency.

Code Block
xmlxml
title/frameworks/CustomBusinessLogic/pom.xml
xml
<?xml version="1.0"?>
<project>
    <!-- parent artifact -->
    <parent>
        <artifactId>frameworks</artifactId>
        <groupId>com.mywostuff</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!-- artifact identity -->
    <artifactId>CustomBusinessLogic</artifactId>
    <groupId>com.mywostuff.frameworks</groupId>

    <!-- specific dependencies -->
    <dependencies>
        <dependency>
            <artifactId>CustomExtensions</artifactId>
            <groupId>${pom.groupId}</groupId>
        </dependency>
    </dependencies>
</project>

...

Here's the definition for /apps/pom.xml which is shared by any sub-modules (i.e., ApplicationA and ApplicationB). Both apps need certain WebObjects frameworks, so we specify those only once for both, here in the parent pom. We also specify Fluffy Bunny Layout, and some maven plugins we want to use. Again, this is for both applications.

Code Block
xmlxml
title/apps/pom.xml
xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <!-- parent artifact -->
    <parent>
        <groupId>com</groupId>
        <artifactId>mywostuff</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!-- artifact identity -->
    <artifactId>apps</artifactId>
    <groupId>com.mywostuff</groupId>
    <packaging>pom</packaging>

    <!-- modules -->
    <modules>
        <module>ApplicationA</module>
        <module>ApplicationB</module>
    </modules>

    <!-- specific dependencies (for modules) -->
    <dependencies>
        <!-- wonder frameworks -->
        <dependency>
            <artifactId>ERExtensions</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWOExtensions</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
        </dependency>

        <!-- project libs -->
        <dependency>
            <artifactId>CustomExtensions</artifactId>
            <groupId>${my.frameworks.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>CustomBusinessLogic</artifactId>
            <groupId>${my.frameworks.groupId}</groupId>
        </dependency>

        <!-- webobjects dependencies -->
        <dependency>
            <artifactId>JavaFoundation</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaJDBCAdaptor</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWebObjects</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaEOControl</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaEOAccess</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaWebObjects</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>JavaXML</artifactId>
            <groupId>${webobjects.groupId}</groupId>
        </dependency>
    </dependencies>

    <!-- build config (for modules) -->
    <build>
        <sourceDirectory>src</sourceDirectory>
        <testSourceDirectory>tests</testSourceDirectory>
        <resources>
            <resource>
                <targetPath>Resources</targetPath>
                <filtering>false</filtering>
                <directory>Components</directory>
            </resource>
            <resource>
                <targetPath>Resources</targetPath>
                <filtering>false</filtering>
                <directory>Resources</directory>
            </resource>
            <resource>
                <targetPath>WebServerResources</targetPath>
                <filtering>false</filtering>
                <directory>WebServerResources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-wolifecycle-plugin</artifactId>
                <groupId>org.objectstyle.woproject.maven2</groupId>
                <version>2.0.15</version>
                <extensions>true</extensions>
                <configuration>
                    <source>${java.target}</source>
                    <target>${java.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <javadocVersion>${java.target}</javadocVersion>
                    <locale>en-AU</locale>
                    <minmemory>128m</minmemory>
                    <maxmemory>512m</maxmemory>
                </configuration>
            </plugin>
            <!--
            TODO build numbering
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>maven-buildnumber-plugin</artifactId>
                <version>0.9.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>create</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <doCheck>true</doCheck>
                    <doUpdate>true</doUpdate>
                </configuration>
            </plugin>
            -->
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.target}</source>
                    <target>${java.target}</target>
                </configuration>
            </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

With most stuff specified in the parent pom, ApplicationA needs only to specify its parent, its idenity, and add a couple of extra specific dependencies to those inherited from its parent.

Code Block
xmlxml
title/apps/ApplicationA/pom.xml
xml
<?xml version="1.0"?>
<project>
    <modelVersion>4.0.0</modelVersion>

    <!-- parent artifact -->
    <parent>
        <artifactId>apps</artifactId>
        <groupId>com.mywostuff</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../apps</relativePath> <!-- e.g., (optional) if your app is under /trunk -->
    </parent>

    <!-- artifact identity -->
    <artifactId>ApplicationA</artifactId>
    <groupId>com.mywostuff.apps</groupId>
    <packaging>woapplication</packaging> <!-- woproject specific packaging -->

    <!-- specific properties -->
    <properties>
        <!-- general properties -->
        <mainclass>your.app.Application</mainclass>
    </properties>

    <!-- specific dependencies -->
    <dependencies>
        <!-- wonder frameworks -->
        <dependency>
            <artifactId>Ajax</artifactId>
            <groupId>${wonder.ajax.groupId}</groupId>
        </dependency>
        <dependency>
            <artifactId>ERCaptcha</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
            <!-- requires jcaptcha-all below -->
        </dependency>
        <dependency>
            <artifactId>WOOgnl</artifactId>
            <groupId>${wonder.common.groupId}</groupId>
        </dependency>

        <!-- general libs -->
        <dependency>
            <artifactId>jcaptcha-all</artifactId>
            <groupId>com.octo.captcha</groupId>
        </dependency>
        <dependency>
            <artifactId>commons-collections</artifactId>
            <groupId>commons-collections</groupId>
        </dependency>
        <dependency>
            <groupId>ognl</groupId>
            <artifactId>ognl</artifactId>
        </dependency>
    </dependencies>
</project>

...