依开发环境需要,有时我们并不会运行到框架打包,这时就需要依靠Maven进行普通java程序的打包。
打包可运行jar包(不包括依赖的其他jar包)
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>Test</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version>
<configuration> <archive> <manifest> <!--这里改成你的main方法类路径--> <mainClass>com.dll.test.PlanMethod</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>
打包可运行jar包(包括依赖的其他jar包)
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>Test</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <archive> <manifest> <!--这里改成你的main方法类路径--> <mainClass>com.dll.test.PlanMethod</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <!-- 这里用于继承合并 --> <phase>package</phase> <!-- 绑定到打包阶段 --> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
打包可依赖jar包和可运行jar包(包括依赖的其他jar包)
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.example</groupId> <artifactId>Test</artifactId> <version>1.0-SNAPSHOT</version> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <configuration> <archive> <manifest> <!--这里改成你的main方法类路径--> <mainClass>com.dll.test.PlanMethod</mainClass> </manifest> </archive> <!-- 配置生成的可运行jar名称 --> <descriptorRefs> <descriptorRef>exec</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <!-- 这里用于继承合并 --> <phase>package</phase> <!-- 绑定到打包阶段 --> <goals> <goal>single</goal> </goals> </execution> <!-- 在执行package动作的时候,自动打包 --> <execution> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
Java程序打包
如果大家是IDEA、Eclipse的话可运行clear、install打包,如果不是的可用命令打包
#运行maven命令打包程序(在pom.xml目录下运行)
mvn package
文章转载至:https://blog.csdn.net/strongyoung88/article/details/54097830