使用IntelliJ我刚刚创建了一个新的Maven项目,并将以下内容添加到pom文件http://undertow.io/downloads.html中,并将以下内容添加到Main.java文件中http://undertow.io/index.html
现在,如果我运行代码一切正常,但我如何将其作为一个"胖罐"它将包含pom文件中的所有依赖项,并且我只能java -jar my.jar
运行?就像你可以使用Spring Boot应用程序一样。
答案 0 :(得分:16)
Maven Shade Plugin做得很好。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>package.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
答案 1 :(得分:6)
1)将Spring-boot-maven-plugin
添加到pom.xml文件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.0.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
2)将包装更改为jar
<packaging>jar</packaging>
3)mvn package
将创建可执行jar。