Maven-02

5.第三个Maven工程
        ①设置通过Maven创建的工程的JDK版本——一劳永逸
                [1]打开settings.xml文件
                [2]找到profiles标签
                [3]加入如下配置

                    <profile>
				<id>jdk-1.7</id>
				<activation>
					<activeByDefault>true</activeByDefault>
					<jdk>1.7</jdk>
				</activation>
				<properties>
					<maven.compiler.source>1.7</maven.compiler.source>
					<maven.compiler.target>1.7</maven.compiler.target>
					<maven.compiler.compilerVersion>1.7</maven.compiler.compilerVersion>
				</properties>
			</profile>

                    ②工程坐标
                            groupId:com.atguigu.maven
                            ArtifactId:MakeFriends
                            Package:com.atguigu.maven
                    ③在src/main/java中新建类com.atguigu.maven.MakeFriends

public String makeFriends(String name){
			HelloFriend friend = new HelloFriend();
			friend.sayHelloToFriend("litingwei");
			String str = "Hey,"+friend.getMyName()+" make a friend please.";
			System.out.println(str);
			return str;
		}

                ④在src/test/java中新建类com.atguigu.maven.MakeFriendsTest

package com.atguigu.maven;
		import static junit.framework.Assert.assertEquals;
		import org.junit.Test;
		public class MakeFriendsTest {
			@Test
			public void testMakeFriends(){		
				MakeFriends makeFriend = new MakeFriends();
				String str = makeFriend.makeFriends("litingwei");
				assertEquals("Hey,John make a friend please.",str);
			}
		}

                ⑤添加依赖信息

<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.9</version>
			<scope>test</scope>
		</dependency>
		<dependency>
	    	<groupId>com.atguigu.maven</groupId>
	    	<artifactId>HelloFriend</artifactId>
	    	<version>0.0.1-SNAPSHOT</version>
	    	<type>jar</type>
	    	<scope>compile</scope>
		</dependency>

                ⑥在Eclipse环境下执行Maven命令:右击pom.xml选择run as 中的命令执行即可

6.测试依赖的范围对传递性的影响

                ①在Hello中添加对spring-core的依赖

                <dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-core</artifactId>
			<version>4.0.0.RELEASE</version>
			<scope>compile</scope>
		</dependency>

                ②在HelloFriend中查看spring-core是否被加入了运行时环境
                ③将Hello中对spring-core的依赖范围修改为test,再到HelloFriend中检查
                ④将Hello中对spring-core的依赖范围修改为provided,再到HelloFriend中检查
                ⑤结论:非compile范围的依赖不能传递,必须在有需要的工程中单独加入
7.测试依赖原则
                ①路径最短者优先
                    [1]在Hello中依赖log4j-1.2.17

                        <dependency>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
				<version>1.2.17</version>
			</dependency>

                    [2]在HelloFriend中依赖log4j-1.2.14

                        <dependency>
				<groupId>log4j</groupId>
				<artifactId>log4j</artifactId>
				<version>1.2.14</version>
			</dependency>

                    [3]查看MakeFriends中自动引入的log4j是哪个版本
                ②路径相同时先声明者优先
                    [1]创建OurFriends工程,依赖log4j-1.2.17
                    [2]让MakeFriends依赖OurFriends
                    [3]测试MakeFriends中,HelloFriend和OurFriends依赖的先后顺序和引入的log4j版本之间的关系
8.创建Web工程
                ①ServletAPI依赖

	        <dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
			<scope>provided</scope>
		</dependency>
		

                ②JSPAPI依赖

                <dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1.3-b06</version>
			<scope>provided</scope>
		</dependency>

9.Web工程自动部署

<build>
		<finalName>AtguiguWeb</finalName>
		<plugins>
			<plugin>
				<groupId>org.codehaus.cargo</groupId>
				<artifactId>cargo-maven2-plugin</artifactId>
				<version>1.2.3</version>
				<configuration>
					<container>
						<containerId>tomcat6x</containerId>
						<home>D:\DevInstall\apache-tomcat-6.0.39</home>
					</container>
					<configuration>
						<type>existing</type>
						<home>D:\DevInstall\apache-tomcat-6.0.39</home>
						<!-- 如果Tomcat端口为默认值8080则不必设置该属性 -->
						<properties>
							<cargo.servlet.port>8989</cargo.servlet.port>
						</properties>
					</configuration>
				</configuration>
				<executions>  
					<execution>  
						<id>cargo-run</id>  
						<phase>install</phase>  
						<goals>  
							<goal>run</goal>  
						</goals>  
					</execution>  
				</executions>
			</plugin>
		</plugins>
	</build>

10.继承
                    ①创建Parent工程,打包方式为pom
                    ②收集所有非compile范围的依赖信息,使用dependencyManagement标签统一管理

                <dependencyManagement>
			<dependencies>
				<dependency>
					<groupId>junit</groupId>
					<artifactId>junit</artifactId>
					<version>4.9</version>
					<scope>test</scope>
				</dependency>
			</dependencies>
		</dependencyManagement>

                    ③在各个子工程中引用父工程

                <parent>
			<groupId>com.atguigu.maven</groupId>
			<artifactId>Parent</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			
			<!-- 以当前文件为基准查找父工程中pom.xml文件的相对路径 -->
			<relativePath>../Parent/pom.xml</relativePath>
		</parent>

                ④删除子工程中的重复信息
                        groupId
                        artifactid
                ⑤在子工程中找到被父工程管理的依赖信息,删除版本号部分
                ⑥在父工程中统一修改已管理的依赖信息的版本号,看是否能够控制所有子工程
11.聚合
在总的聚合工程中加入如下信息

        <modules>
		<module>../Hello</module>
		<module>../HelloFriend</module>
		<module>../MakeFriends</module>
	</modules>

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
idea终端:PS C:\Users\16283\Desktop\springbootc8hzm> mvn clean install [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building springboot-schema 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: http://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/2.2.2.RELEASE/spring-boot-maven-plugin-2.2.2.RELEASE.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.207 s [INFO] Finished at: 2023-07-22T20:02:37+08:00 [INFO] Final Memory: 9M/245M [INFO] ------------------------------------------------------------------------ [ERROR] Plugin org.springframework.boot:spring-boot-maven-plugin:2.2.2.RELEASE or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.springframew ork.boot:spring-boot-maven-plugin:jar:2.2.2.RELEASE: Could not transfer artifact org.springframework.boot:spring-boot-maven-plugin:pom:2.2.2.RELEASE from/to central (http://repo.maven. apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-maven-plugin/2.2.2.RELEASE/spring-boot-maven-plugin-2.2.2.RELEASE. pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
07-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值