0
点赞
收藏
分享

微信扫一扫

Java 打maven包 可以使用java -jar 运行

有时候我们想打一个jar包 像springboot项目一样运行 java jar 来运行,但是直接使用maven引入相关的依赖直接打包无法使用。

这时需要在pom.xml 中添加一个plugin    

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.3.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <!-- 指定启动类  这里填写自己main方法所在得类路径-->
                        <mainClass>xxx.xxx.xxx</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

这个时候在打包会生成两个jar

使用 xxxxx-jar-with-dependencies.jar 这个包来使用 java -jar 命令来直接运行即可。

举报

相关推荐

0 条评论