可用的maven。pom.xml文件的模板

本文详细介绍了Maven项目配置文件的结构,包括依赖项如JUnit、Servlet API、Freemarker和MySQL连接器的版本,以及如何设置Maven的编译环境为JDK 1.8。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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>xyz.jangle</groupId>
	<artifactId>xxx.yyy</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
                <!-- Servlet API jsp页面需要 -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
			<scope>provided</scope>
		</dependency>
		<!-- 引入Freemarker的依赖 -->
		<dependency>
			<groupId>org.freemarker</groupId>
			<artifactId>freemarker</artifactId>
			<version>2.3.23</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>5.1.31</version>
		</dependency>
	</dependencies>
	<build>
		<pluginManagement>
			<plugins>
                                <!-- 设置MAVEN的编译的JDK版本为1.8 -->
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>2.3.2</version>
					<configuration>
						<source>1.8</source>
						<target>1.8</target>
						<encoding>UTF-8</encoding>
					</configuration>
				</plugin>
			</plugins>
		</pluginManagement>
	</build>
</project>

可导出可执行jar: 

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>xyz.jangle</groupId>
  <artifactId>jdbc.test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
  			<dependency>
			    <groupId>mysql</groupId>
			    <artifactId>mysql-connector-java</artifactId>
			    <version>8.0.22</version>
			</dependency>
  </dependencies>
  
  <build>
		<sourceDirectory>src\main\java</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.7.0</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
	        <!-- 配置maven-assembly-plugin插件  用于生产可执行jar-->
	        <plugin>
	            <artifactId>maven-assembly-plugin</artifactId>
	            <configuration>
	                <!-- 指定打包方式为jar-with-dependencies,即一个包含所有依赖的可执行jar -->
	                <archive>
	                    <manifest>
	                        <!-- 指定主类,这是你的应用程序的入口点 -->
<!-- 	                        <mainClass>xyz.jangle.string.test.StringTest</mainClass> -->
	                        <mainClass>xyz.jangle.hello.test.HelloWorld</mainClass>
	                    </manifest>
	                </archive>
	                <descriptorRefs>
	                    <descriptorRef>jar-with-dependencies</descriptorRef>
	                </descriptorRefs>
	            </configuration>
	            <executions>
	                <execution>
	                    <!-- 绑定到打包生命周期阶段 -->
	                    <phase>package</phase>
	                    <goals>
	                        <goal>single</goal>
	                    </goals>
	                </execution>
	            </executions>
	        </plugin>
		</plugins>
	</build>
</project>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值