使用Maven

项目结构:

src
	- main
		- java
		- resources
	- test
		- java
pom

项目构建命令:

mvn compile				# 编译
mvn clean				# 清理
mvn test				# 测试
mvn package				# 打包
mvn install				# 安装到本地仓库

依赖管理,在 pom.xml 文件中,进行配置可以手写,也可以 alt + insert,使用 generate 功能

groupId: 隶属组织名称
artifactId: 所使用的模块名称
version: 版本号
	<!-- 指定 pom 的模型版本 -->
	<modelVersion>4.0.0</modelVersion>
    <dependencies>
        <!--导入 mysql 驱动 jar 包-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.48</version>
        </dependency>
        <!--导入 druid jar 包-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.12</version>
        </dependency>
    </dependencies>

	<!-- 构建 -->
	<build>
		<!-- 设置插件 -->
		<plugins>
		
			<!-- 具体的某个插件 -->
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.1</version>
				<configuration>
					<port>80</port>
					<path>/</path>
				</configuration>
			</plugin>
			
		</plugins>
	</build>

依赖传递:
当依赖中出现相同的资源时,层积越深,优先级越低

<dependencies>

	<dependency>
		<groupId>com.itheima</groupId>
		<artifactId>project03</artifactId>
		<version>1.0-SNAPSHOT</version>
	
		<!-- 排除依赖 -->	
		<!-- 控制当前项目是否使用其直接依赖所包含的子依赖项 -->
		<!-- 依赖project03, 但不使用project03中的log4j依赖 -->
		<exclusions>
			<exclusion>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
			</exclusion>
		</exclusions>
	
	</dependency>
	
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.12</version>
		<!-- 表示该依赖项不能被传递使用,只能用于当前层级项目 -->
		<optional>true</optional>
	</dependency>
</dependencies>

依赖范围:控制依赖的jar包作用的范围
作用范围:主程序有效(main文件夹范围内),测试程序有效(test文件夹范围内),运行时有效/是否参与打包(package指令范围内)

# 控制 dependency元素的使用范围
<scope></scope>
# 默认范围, 在项目的所有类路径中都可用
# 具有传递性
compile(default)	# 在任何地方使用, 范例 log4j

# 该依赖对于应用程序的正常使用不是必须的, 仅适用于测试
# 不具有传递性
test				# 只在测试程序test文件夹中使用, 范例 junit

# tomcat_Web容器中也有servletAPI,为了避免版本冲突,所以打包的时候不参与
# 被包含在编译和测试的类路径中, 运行时则由JDK或者容器自己提供
# 不具有传递性
provided			# 在 main 和 test中使用, 不参与打包, 范例 servlet-api

# 被包含在运行和测试的类路径中, 但不包括编译类路径, 编译时并不需要该依赖项
runtime				# 只参与打包, 范例 jdbc

# This scope is only supported on a dependency of type pom in the <dependencyManagement> section.
# It indicates the dependency is to be replaced with the effective list of dependencies in the specified POM's <dependencyManagement> section.
import

带有依赖范围的模块在进行传递时,作用范围将受到影响

			|	compile		test 	provided	runtime		# 直接依赖项所标注的范围
—— —— —— —— — —— —— —— —— —— —— —— —— —— —— —— —— —— —
compile		|	compile		test  	provided 	runtime
test		|	# 最终子依赖项的作用范围, 为空表示不被引用到
provided	|	
runtime		|	runtime 	test	provided	runtime
# 子依赖项上标注的范围
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值