美文网首页
为Maven指定主启动类

为Maven指定主启动类

作者: JohnYuCN | 来源:发表于2020-12-03 16:04 被阅读0次

    一、普通Maven项目

    1. 为package阶段添加一个shade的目标
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <transformers>
                                    <transformer
                                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                        <mainClass>cn.johnyu.MyApp</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
               
            </plugins>
        </build>
    
    1. 重新配置package阶段的插件:
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>cn.johynyu.MyApp</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    二、SpringBoot项目:

    <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <mainClass>cn.johnyu.App</mainClass>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    

    相关文章

      网友评论

          本文标题:为Maven指定主启动类

          本文链接:https://www.haomeiwen.com/subject/ifgmwktx.html