Maven 如何为项目的子模块指定父POM?

Maven 如何为项目的子模块指定父POM?,maven,Maven,有一个Spring项目,其中包含模块: 项目的pom.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:

有一个Spring项目,其中包含模块:

项目的
pom.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>
        <groupId>com.bni.wfcredit</groupId>
        <artifactId>bni-wfcredit-root</artifactId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>bni-wfcredit-root</relativePath>
    </parent>

    <artifactId>bni-wfcredit</artifactId>
    <packaging>pom</packaging>
    <name>Bni wfcredit</name>
    <url>http://maven.apache.org</url>

    <modules>
        <module>bni-wfcredit-root</module>
  </modules>
</project>

那么如何指定父级呢?

多模块结构应该是这样的--

首先,检查父项目是否在本地存储库中?如果没有,那么您需要检查它并自己构建它

您需要向
添加一个空的
,以便它从存储库解析父pom

<parent>
   <groupId>com.bni.wfcredit</groupId>
   <artifactId>bni-wfcredit-root</artifactId>
   <version>1.0-SNAPSHOT</version>
   <relativePath></relativePath>
</parent>

com.bni.wfcredit

.

在编译时从配置的maven存储库加载父pom。不是根项目上的,也不是模块中的

要在本地安装父pom,需要在父pom项目上运行以下命令:

mvn安装

或者,如果您已经有了父pom项目jar

mvn安装:安装文件-Dfile=文件路径


有关更多信息,请参阅和(如何创建JAR并将其安装到本地存储库?

好的,我找到了解决方案(感谢大家的回答):我将主项目的相对路径设置为:
bni wfcredit root/pom.xml
,并将其他模块的相对路径设置为
。/bni wfcredit root/pom.xml
(除了根模块:)

我的案例与往常不同:父模块与您提到的不同,但它是主项目下的一个模块!那么如何从外部pom指向模块
bni wfcredit root
?基于给定的结构,不应定义relativePath,因为默认值为
。/pom.xml
。。。!
[ERROR] The build could not read 8 projects -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 5, column 13
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT in JasperReports (http://jaspersoft.artifactoryonline.com/jaspersoft/third                                                                                      -party-ce-artifacts/) and 'parent.relativePath' points at wrong local POM @ line 5, column 13
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 7, column 10
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 10
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 7, column 10
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 10
[WARNING] 'parent.relativePath' points at com.bni.wfcredit:bni-wfcredit instead of com.bni.wfcredit:bni-wfcredit-root, please verify your project structure @ line 7, column 10
[FATAL] Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column 10

        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:364)
        at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:637)
        at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:586)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:229)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR]
[ERROR]   The project com.bni.wfcredit:bni-wfcredit-common:1.0-SNAPSHOT (D:\Projets\bni-wfcredit\bni-wfcredit-common\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6, column 1                                                                                      3 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT
        at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:159)
        at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:817)
        at org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:669)
        at org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:307)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:411)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:380)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:496)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:380)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:496)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:380)
        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:344)
        at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:637)
        at org.apache.maven.DefaultMaven.getProjectsForMavenReactor(DefaultMaven.java:586)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:229)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:459)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:262)
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:239)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.resolveArtifact(DefaultRepositorySystem.java:295)
        at org.apache.maven.project.ProjectModelResolver.resolveModel(ProjectModelResolver.java:155)
        ... 25 more
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact com.bni.wfcredit:bni-wfcredit-root:pom:1.0-SNAPSHOT
        at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:449)
        ... 29 more
parent
├── pom.xml
├── module
    ├── pom.xml
<parent>
   <groupId>com.bni.wfcredit</groupId>
   <artifactId>bni-wfcredit-root</artifactId>
   <version>1.0-SNAPSHOT</version>
   <relativePath></relativePath>
</parent>