简体   繁体   中英

Multi-module Spring Boot and start-class

I have made my application multi-module with the plan of eventually splitting them into multiple repos.

I'm having problems figuring out how to make mvn spring-boot:run work with my layout (which may be the problem).

actually directory structure is

 xenoterracide/
     rpf/
     rpf-application/

when I run mvn test from xenoterracide that passes fine, and when I start my Application class that works fine.

if I cd into rpf-application and run mvn compile it tells me that it can't find the dependencies, I'm guessing this is because things are meant to be run from the repository root.

[INFO] ------------------------------------------------------------------------
[INFO] Building rpf-application 0.1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.xenoterracide:security-rbac-jpa:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:http:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:rpf-domain:jar:0.1.0-SNAPSHOT is missing, no dependency information available
[WARNING] The POM for com.xenoterracide:rpf-liquibase:jar:0.1.0-SNAPSHOT is missing, no dependency information available

if I try to set the start-class in the xenoterracide/pom.xml it tells me it can't find the class (because of course it's in rpf-application).

rpf-application/pom.xml

<parent>
    <artifactId>rpf</artifactId>
    <groupId>com.xenoterracide</groupId>
    <version>0.1.0-SNAPSHOT</version>
    <relativePath>../rpf/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>rpf-application</artifactId>

<properties>
    <start-class>com.xenoterracide.RpfApplication</start-class>
</properties>

<dependencies>
    <!-- internal -->
    <dependency>
        <groupId>com.xenoterracide</groupId>
        <artifactId>security-rbac-jpa</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.xenoterracide</groupId>
        <artifactId>http</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.xenoterracide</groupId>
        <artifactId>rpf-domain</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.xenoterracide</groupId>
        <artifactId>rpf-liquibase</artifactId>
        <version>0.1.0-SNAPSHOT</version>
    </dependency>
...

rpf/pom.xml

<parent>
    <artifactId>xenoterracide</artifactId>
    <groupId>com.xenoterracide</groupId>
    <version>0.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>rpf</artifactId>
<packaging>pom</packaging>
<modules>
    <module>../rpf-domain</module>
    <module>../rpf-application</module>
    <module>../rpf-liquibase</module>
</modules>

pom.xml

<modelVersion>4.0.0</modelVersion>

<groupId>com.xenoterracide</groupId>
<artifactId>xenoterracide</artifactId>
<packaging>pom</packaging>
<version>0.1.0-SNAPSHOT</version>
<modules>
    <module>util</module>
    <module>http</module>
    <module>security-rbac-api</module>
    <module>security-rbac-jpa</module>
    <module>hibernate</module>
    <module>entity-jpa</module>
    <module>rpf</module>
    <module>test-repositories</module>
    <module>entity-api</module>
</modules>
<properties>
    <!-- use UTF-8 for everything -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<parent>
    <groupId>io.spring.platform</groupId>
    <artifactId>platform-bom</artifactId>
    <version>1.1.2.RELEASE</version>
 </parent>

how can I make mvn spring-boot:run work from either the root of the repository (xenoterracide) or from rpf-application ?

I also have a multi-project Spring Boot app and you can't do it from the parent since there could be multiple modules and it would not know which to run. You can do it from the child module if you first install the rest of the project to local Maven repository. So from your xenoterracide run:

mvn install

Assuming that works it will put your SNAPSHOT versions into your local repository. You can then change to your rpf-application and then run:

mvn spring-boot:run

I've never really used this as a way to run it so maybe you can explain what your need is and we can see if there is another way that may be better. I did do it with my project and it works but you have to be conscious of where the working directory is for your environment specific configuration files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM