Question

I'd like to create multimodule standalone application with maven.

In my case I'd like to make 'Loader' project (.jar) contains all other projects. But now I have just set of .jar files (loader.jar, crawler1.jar ... etc)

loader's .pom:

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

    <groupId>com.javanix.jmetalcrawler</groupId>
    <artifactId>loader</artifactId>
    <version>1.0</version>


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

</project>

subproject's .pom:

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

    <groupId>com.javanix.jmetalcrawler</groupId>
    <artifactId>Crawler-1</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>com.javanix.jmetalcrawler</groupId>
            <artifactId>loader</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

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

</project>

parent's .pom:

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

    <groupId>com.javanix.jmetalcrawler</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>
    <name>jMetalCrawler</name>

    <modules>
        <module>Crawler-1</module>
        <module>Loader</module>
    </modules>


</project>

Lifecycle:

  1. compile 'Loader' (has interfaces/abstract classes)
  2. compile/package 'crawler1' (as it depends on 'Loader' project)
  3. compile/package 'crawler2' (as it depends on 'Loader' project)
  4. package loader with compiled 'crawler' projects

P.S.:

  1. Thanks to Adrian Shum , he gave an idea to make my project clearer
  2. After restructure my project in 'Launcher' project we can add dependencies via maven-assembly-plugin (@see http://rombertw.wordpress.com/2010/05/14/maven-recipe-building-an-aggregate-jar/)
Was it helpful?

Solution

I'd suggest project structure like this:

loader  (POM, multi-module)
  + loader-api  (JAR)
  + crawler1    (JAR, depends on loader-api)
  + crawler2    (JAR, depends on loader-api)
  + loader-app  (JAR, depends on loader-api, crawler1, crawler2.  
                 The standalone app is built here)

By splitting the API that crawlers depends and the app itself, the whole project structure is much easier to manage. And, it is more modularized too, as we are no longer mixing the API with the app

OTHER TIPS

If you by "multimodule standalone application with maven" mean a self-contained, executable jar that contains all its dependencies then onejar-maven-plugin may be what you are looking for. See the documentation for usage examples.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top