mvn install 报错Unable to find main class
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.6.RELEASE:repackage (repackage) on project motai-common: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.2.6.RELEASE:repackage failed: Unable to find main class
简单install一个自定义的工具包到maven本地仓库 报错
寻思也不需要主类啊
仔细检查pom发现少了<packaging>jar</packaging>
添加后执行错误依旧
再仔细看错误repackage failed
应该是install之前打包出错 大概判断是spring-boot:repackage插件的问题
果然父模块pom中使用了它
不太了解这个打包插件 不怕,查查官方文档
spring-boot:repackage 描述里有这句话
Repackages existing JAR and WAR archives so that they can be executed from the command line using java -jar. With layout=NONE can also be used simply to package a JAR with nested dependencies (and no main class, so not executable).
大概就是说可执行的jar包需要配置主类 如果你不配置主类想获得一个不可直接java -jar执行的jar包 就配置layout=NONE
在需要打包的模块pom中添加:
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <layout>NONE</layout> </configuration> </plugin> </plugins> </build>
成功解决问题 当然也可以在工程中不使用该插件 也可以在父模块统一打包
思考:
install成功发现一条警告信息dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-test:jar
检查发现是父模块中test包写了两次
由此想到 此次打包时把父模块的依赖也打进去了 徒增工具包的大小
那么改如何剔除这些无用依赖呢
查到可以这样在插件中手动排除
不过这样感觉有点麻烦 ,还有一种就是断绝父子模块的关系 哈哈哈
不知道有没有其他更方便的方法 可以排除无关的jar包
想到一个偷懒方法 打包后直接用压缩软件全部delete