美文网首页
maven生成jar,提示没有“没有主清单属性”

maven生成jar,提示没有“没有主清单属性”

作者: 阳光的技术小栈 | 来源:发表于2018-04-19 10:48 被阅读1292次

修改pom.xml

增加以下代码:

    <build>
        <finalName>App</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>App</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

其中的

<mainClass>App</mainClass>

是主函数的类,并要求全路径,比如

<mainClass>com.project.App</mainClass>

然后再次使用maven命令clean、compile、package命令打包,并使用其中类似App-1.0-SNAPSHOT.jar的包。

相关文章

网友评论

      本文标题:maven生成jar,提示没有“没有主清单属性”

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