How to create Jar from submodules of module?

2020-03-30 17:35发布

I have this java maven project structure

- parentModule
    - firstChildModule
    - firstChildModule
    - firstChildModule
        - secondChildModule -> **jar**
            - thirdChildModule
            - thirdChildModule
            - thirdChildModule

And I want to package the secondChildModule module as a jar containing its submodules.

I have tried to set the packaging type to pom but an exception is thrown stating that 'packaging' with value 'jar' is invalid.

So my question is how to do this the right way? I mention that only the thirdChildModule module types will contain source code.

here are the sources for firstChildModule, secondChildModule and

firstChildModule

<?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">
    <parent>
        <artifactId>parentModule</artifactId>
        <groupId>com.company</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>firstChildModule</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>secondChildModule</module>
    </modules>

</project>

secondChildModule

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

    <parent>
        <groupId>com.company</groupId>
        <artifactId>firstChildModule</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>secondChildModule</artifactId>
    <packaging>pom</packaging>

    <name>Second Child Module</name>

    <modules>
        <module>thirdChildModule01</module>
        <module>thirdChildModule02</module>
        <module>thirdChildModule0</module>
    </modules>

</project>

thirdChildModule

 <?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">
    <parent>
        <artifactId>secondChildModule</artifactId>
        <groupId>com.company</groupId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>thirdChildModule01</artifactId>

</project>

0条回答
登录 后发表回答