英文:
Maven, Inherit pom module
问题
我正在编写一个项目,但在编译项目时遇到了问题。在我根据pom文件中显示的方式导入了必要的依赖后,我无法运行项目。
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>universeBySali-web</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<properties>
<java.version>13.0.2</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>15.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.sali</groupId>
<artifactId>universeBySali-ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
pom文件显示的错误如下:
项目构建错误:POM org.springframework.boot:universeBySali-web:1.3.6.RELEASE (C:\Users\User\Desktop\Materiale\Desktop\Java Projects\universeBySali\universeBySali-web\pom.xml) 的'parent.relativePath'指向 com.sali:universeBySali 而不是 org.springframework.boot:spring-boot-starter-parent,请验证您的项目结构
该pom文件具有如下所示的父pom:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sali</groupId>
<artifactId>universeBySali</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>universeBySali-Model</module>
<module>universeBySali-repository</module>
<module>universeBySali-service</module>
<module>universeBySali-util</module>
<module>universeBySali-web</module>
<module>universeBySali-ui</module>
</modules>
</project>
有人能告诉我我做错了什么吗?谢谢
英文:
I am writing a project but I encountered a problem compiling my project. After I imported the necessary dependencies, as shown on the pom file, I couldnt run the project.
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>universeBySali-web</artifactId>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
</parent>
<properties>
<java.version>13.0.2</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>15.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.sali</groupId>
<artifactId>universeBySali-ui</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
The error that it shows on the pom file is as follows:
Project build error: 'parent.relativePath' of POM org.springframework.boot:universeBySali-web:1.3.6.RELEASE (C:\Users\User\Desktop\Materiale\Desktop\Java Projects\universeBySali\universeBySali-web\pom.xml) points at com.sali:universeBySali instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure
This pom file has a parent pom as shown below:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sali</groupId>
<artifactId>universeBySali</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>universeBySali-Model</module>
<module>universeBySali-repository</module>
<module>universeBySali-service</module>
<module>universeBySali-util</module>
<module>universeBySali-web</module>
<module>universeBySali-ui</module>
</modules>
</project>
Can somebody tell me what I am doing wrong?? Thanks
答案1
得分: 0
默认情况下,Maven假定父项目具有以下relativePath
路径:../pom.xml
。
Maven将尝试匹配groupId/artifactId/version
,如果失败则会发出警告并使用“外部”父项目。
为确保Maven不会在多模块中尝试解析父项目,您应该在父项目中添加<relativePath/>
。
英文:
By default Maven assumes the parent has the following relativePath: ../pom.xml
.
Maven will try to match match the groupId/artifactId/version, if it doesn't succeed a warning is thrown and an "external" parent is used.
To ensure Maven won't try to solve the parent as part of your multimodule, you should add <relativePath/>
to the parent.
专注分享java语言的经验与见解,让所有开发者获益!
评论