A
创建一个入门的spring-boot的web项目,mvn package打包,启动没问题;
B
创建一个父工程yemei,修改为pom,创建maven模块项目yemei-admin,yemei-service,
1.yemei-admin添加yemei-service的maven 依赖
eclipse启动正常;
到yemei-admin下进行打包
[ERROR] Failed to execute goal on project yemei2-admin: Could not resolve dependencies for project com:yemei2-admin:jar:0.0.1-SNAPSHOT: Could not find artifact com:yemei2
-service:jar:0.0.1-SNAPSHOT -> [Help 1]
提示是缺少依赖,那先对yemei-service进行install
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project yemei2-service: Execution default of goal or
g.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]
网上搜索的结论:
1.项目内有两个带有main方法的类并且都使用了@SpringBootApplication注解
2.有两个main方法并且所在类都没有使用@SpringBootApplication注解
yemei-service显然是第二种
在yemei-service的pom.xml中添加如下配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>NONE</layout>
</configuration>
</plugin>
</plugins>
</build>
原文地址:https://www.cnblogs.com/thinking-better/p/7827368.html
install成功,
进入admin继续执行mvn package报错:
[ERROR] Failed to execute goal on project yemei2-admin: Could not resolve dependencies for project com:yemei2-admin:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at
com:yemei2-service:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com:yemei2-service:jar:0.0.1-SNAPSHOT: Could not find artifact com:yemei:pom:0.0.1-SNAPSHOT
猜测父项目也需要install到maven库中
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project yemei2-admin: Compilation failure: Compilation failure:
[ERROR] /F:/workspace-das/yemei2/yemei2-admin/src/main/java/com/yemei/controller/HomeController.java:[10,25] 程序包com.yemei.service不存在
猜测:将打出的jar包添加到admin项目中,也不能正确引用service类,是不是service项目执行package出来的jar包有问题?
继续找资料
最后解决,需要在“被引用”项目的pom.xml中添加构建配置
<configuration>
<classifier>exec</classifier>
</configuration>
最后贴出service的完整配置
<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</groupId>
<artifactId>yemei</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>yemei2-service</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<layout>NONE</layout>
</configuration>
</plugin>
</plugins>
</build>
</project>
创建一个入门的spring-boot的web项目,mvn package打包,启动没问题;
B
创建一个父工程yemei,修改为pom,创建maven模块项目yemei-admin,yemei-service,
1.yemei-admin添加yemei-service的maven 依赖
eclipse启动正常;
到yemei-admin下进行打包
[ERROR] Failed to execute goal on project yemei2-admin: Could not resolve dependencies for project com:yemei2-admin:jar:0.0.1-SNAPSHOT: Could not find artifact com:yemei2
-service:jar:0.0.1-SNAPSHOT -> [Help 1]
提示是缺少依赖,那先对yemei-service进行install
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) on project yemei2-service: Execution default of goal or
g.springframework.boot:spring-boot-maven-plugin:2.0.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]
网上搜索的结论:
1.项目内有两个带有main方法的类并且都使用了@SpringBootApplication注解
2.有两个main方法并且所在类都没有使用@SpringBootApplication注解
yemei-service显然是第二种
在yemei-service的pom.xml中添加如下配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>NONE</layout>
</configuration>
</plugin>
</plugins>
</build>
原文地址:https://www.cnblogs.com/thinking-better/p/7827368.html
install成功,
进入admin继续执行mvn package报错:
[ERROR] Failed to execute goal on project yemei2-admin: Could not resolve dependencies for project com:yemei2-admin:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at
com:yemei2-service:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com:yemei2-service:jar:0.0.1-SNAPSHOT: Could not find artifact com:yemei:pom:0.0.1-SNAPSHOT
猜测父项目也需要install到maven库中
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project yemei2-admin: Compilation failure: Compilation failure:
[ERROR] /F:/workspace-das/yemei2/yemei2-admin/src/main/java/com/yemei/controller/HomeController.java:[10,25] 程序包com.yemei.service不存在
猜测:将打出的jar包添加到admin项目中,也不能正确引用service类,是不是service项目执行package出来的jar包有问题?
继续找资料
最后解决,需要在“被引用”项目的pom.xml中添加构建配置
<configuration>
<classifier>exec</classifier>
</configuration>
最后贴出service的完整配置
<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</groupId>
<artifactId>yemei</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>yemei2-service</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
<layout>NONE</layout>
</configuration>
</plugin>
</plugins>
</build>
</project>