山西cms建站系统价格,网络营销推广技术分析,家具网站建设规划书,如何提高网站在百度的排名文章目录 一、分模块开发1.1 分模块开发的意义1.2 步骤 二、依赖管理2.1 依赖传递2.2 可选依赖和排除依赖 三、继承与聚合3.1 聚合3.2 继承3.3 聚合和继承区别 四、属性4.1 pom文件的依赖使用属性4.2 资源文件使用属性 五、多环境开发六、跳过测试七、私服7.1 下载与使用7.2 私… 文章目录 一、分模块开发1.1 分模块开发的意义1.2 步骤 二、依赖管理2.1 依赖传递2.2 可选依赖和排除依赖 三、继承与聚合3.1 聚合3.2 继承3.3 聚合和继承区别 四、属性4.1 pom文件的依赖使用属性4.2 资源文件使用属性 五、多环境开发六、跳过测试七、私服7.1 下载与使用7.2 私服仓库分类7.3 私服的本地配置与上传文件 八、案例演示 一、分模块开发
1.1 分模块开发的意义 1.2 步骤
首先将com.itheima.domain模块拆出来建立一个新的模块maven_03然后在maven_02中的pom文件中引入maven_03的依赖将maven_03通过install打包成jar包通过maven_02的compile进行编译校验最后运行程序是否成功
二、依赖管理
2.1 依赖传递 2.2 可选依赖和排除依赖
可选依赖是自己用的依赖可以设置为是否给其他人用解释这里的optional设置为true表示maven_03_pojo依赖只能自己用不能被其他人用
排除依赖是不想用 引用的这个依赖 的下一级依赖解释exclusions表示不想用maven_04_dao下的log4j和mybatis依赖 三、继承与聚合
3.1 聚合 3.2 继承 3.3 聚合和继承区别 父模块
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdmaven_01_parent/artifactIdpackagingpom/packagingversion1.0-SNAPSHOT/version!-- 设置聚合工程的子模块统一管理子模块--modulesmodule../maven_02_ssm/modulemodule../maven_03_pojo/module/modules!-- 父工程的依赖--dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactIdversion5.2.10.RELEASE/version/dependency/dependencies!-- 定义依赖管理: 子依赖可选择使用--dependencyManagementdependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.12/versionscopetest/scope/dependency/dependencies/dependencyManagement/project
子模块
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdmaven_02_ssm/artifactIdpackagingwar/packagingversion1.0-SNAPSHOT/versionnamemaven_02_ssm Maven Webapp/nameurlhttp://maven.apache.org/url!-- 配置当前工程继承parent父工程--parentgroupIdorg.example/groupIdartifactIdmaven_01_parent/artifactIdversion1.0-SNAPSHOT/version!-- parent父工程pom文件的位置--relativePath../maven_01_parent/pom.xml/relativePath/parentdependenciesdependencygroupIdorg.example/groupIdartifactIdmaven_03_pojo/artifactIdversion1.0-SNAPSHOT/version!-- 设置可选依赖true表示仅自己使用其他人无法使用 --optionalfalse/optional!-- 设置排除依赖表示不想使用maven_03_pojo依赖下的mybatis依赖 --exclusionsexclusiongroupIdorg.mybatis/groupIdartifactIdmybatis/artifactId/exclusion/exclusions/dependency!-- 继承父类的依赖不用写版本号父类已写好--dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdscopetest/scope/dependency/dependenciesbuildfinalNamemaven_02_ssm/finalNamepluginsplugingroupIdorg.apache.tomcat.maven/groupIdartifactIdtomcat7-maven-plugin/artifactIdversion2.1/versionconfigurationport80/portpath//path/configuration/plugin/plugins/build
/project四、属性 4.1 pom文件的依赖使用属性 4.2 资源文件使用属性
这里使用pom.xml文件配置src/mian/resourses下的jdbc.properties文件的属性即使用pom文件配置连接数据库需要的参数
五、多环境开发
Maven提供配置多种环境的设定帮助开发者使用过程中快速切换环境 一定要注意mvn 命令要在指定模块下运行不然找不到环境
六、跳过测试
应用场景功能未开发完、快速打包… 方式一 方式二 方式三
七、私服
7.1 下载与使用
Nexus下载地址https://help.sonatype.com/repomanager3/download
下载解压后会有nexus-3.30.1-01和sonatype-work文件夹在nexus-3.30.1-01\bin目录下打开cmd输入指令nexus.exe /run nexus启动服务器
7.2 私服仓库分类 7.3 私服的本地配置与上传文件
第一步建立两个maven2仓库并且在maven-public里面将建好的两个仓库交给其管理记得点击save保存 第二步在本地的maven的setting.xmlapache-maven-3.3.9\conf下文件中配置访问私服的仓库的用户名和密码 同样在setting.xml中配置私服的地址圈红部分改为maven-public 第三步在父工程的pom文件中 最后可以看到私有仓库itheima-release已经上传了文件 注意可以修改pom.xml文件的version版本为release发布版本或snapshot快照版本格式指定放在私服的哪个仓库中 其次想要配置访问中央服务器的地址这里可以改为阿里的 八、案例演示
父工程maven_01_parent
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdmaven_01_parent/artifactIdpackagingpom/packagingversion1.0-SNAPSHOT/version!-- 3.设置聚合工程的子模块统一管理子模块--modulesmodule../maven_02_ssm/modulemodule../maven_03_pojo/module/modules!-- 4.父工程的依赖--dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-webmvc/artifactId!-- 9.使用属性 --version${Spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-jdbc/artifactIdversion${Spring.version}/version/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion${Spring.version}/version/dependencydependencygroupIdorg.mybatis/groupIdartifactIdmybatis/artifactIdversion3.5.6/version/dependencydependencygroupIdorg.mybatis/groupIdartifactIdmybatis-spring/artifactIdversion1.3.0/version/dependencydependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdversion5.1.47/version/dependencydependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.1.16/version/dependencydependencygroupIdjavax.servlet/groupIdartifactIdjavax.servlet-api/artifactIdversion3.1.0/versionscopeprovided/scope/dependencydependencygroupIdcom.fasterxml.jackson.core/groupIdartifactIdjackson-databind/artifactIdversion2.9.0/version/dependency/dependencies!-- 6.定义依赖管理: 子依赖可选择使用--dependencyManagementdependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion${junit.version}/versionscopetest/scope/dependency/dependencies/dependencyManagement!-- 8.定义属性 --propertiesSpring.version5.2.10.RELEASE/Spring.versionjunit.version4.12/junit.versionjdbc.usernameroot/jdbc.username/propertiesbuild!--10.配置指定目录下的文件也能使用上面的属性--resources!--设置资源目录并设置能够解析${}--resource!-- directory../maven_02_ssm/src/main/resources/directory--!-- directory../maven_03_pojo/src/main/resources/directory--!-- 上述可以简化成${project.basedir}--directory${project.basedir}/src/main/resources/directoryfilteringtrue/filteringincludesinclude**/*.properties/includeinclude**/*.xml/include/includes/resource/resourcesplugins!--13.跳过测试--pluginartifactIdmaven-surefire-plugin/artifactIdversion2.12.4/versionconfiguration!--true表示跳过所有测试--skipTestsfalse/skipTests!--排除掉不参与测试的内容--excludesexclude**/BookServiceTest.java/exclude/excludes/configuration/plugin/plugins/build!--12.配置多环境--profiles!--开发环境--profileidenv_dep/idpropertiesjdbc.urljdbc:mysql://127.1.1.1:3306/ssm_db/jdbc.url/properties!--设定是否为默认启动环境--activationactiveByDefaulttrue/activeByDefault/activation/profile!--生产环境--profileidenv_pro/idpropertiesjdbc.urljdbc:mysql://127.2.2.2:3306/ssm_db/jdbc.url/properties/profile!--测试环境--profileidenv_test/idpropertiesjdbc.urljdbc:mysql://127.3.3.3:3306/ssm_db/jdbc.url/properties/profile/profiles!--14.配置当前工程保存在私服中的具体位置--distributionManagementrepositoryiditheima-Release/idurlhttp://localhost:8081/repository/itheima-Release//url/repositorysnapshotRepositoryiditheima-Snapshot/idurlhttp://localhost:8081/repository/itheima-Snapshot//url/snapshotRepository/distributionManagement/project
子工程maven_02_ssm
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdmaven_02_ssm/artifactIdpackagingwar/packagingversion1.0-SNAPSHOT/versionnamemaven_02_ssm Maven Webapp/nameurlhttp://maven.apache.org/url!-- 5. 配置当前工程继承parent父工程--parentgroupIdorg.example/groupIdartifactIdmaven_01_parent/artifactIdversion1.0-SNAPSHOT/version!-- parent父工程pom文件的位置--relativePath../maven_01_parent/pom.xml/relativePath/parentdependenciesdependencygroupIdorg.example/groupIdartifactIdmaven_03_pojo/artifactIdversion1.0-SNAPSHOT/version!-- 1.设置可选依赖true表示仅自己使用其他人无法使用 --optionalfalse/optional!-- 2.设置排除依赖表示不想使用maven_03_pojo依赖下的mybatis依赖 --exclusionsexclusiongroupIdorg.mybatis/groupIdartifactIdmybatis/artifactId/exclusion/exclusions/dependency!-- 7.继承父类的依赖不用写版本号父类已写好--dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdscopetest/scope/dependency/dependenciesbuildfinalNamemaven_02_ssm/finalNamepluginsplugingroupIdorg.apache.tomcat.maven/groupIdartifactIdtomcat7-maven-plugin/artifactIdversion2.1/versionconfigurationport80/portpath//path/configuration/plugin!--11.打包时忽略检查web.xml文件--plugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-war-plugin/artifactIdversion3.2.3/versionconfigurationfailOnMissingWebXmlfalse/failOnMissingWebXml/configuration/plugin/plugins/build
/project
子工程maven_03_pojo
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsdmodelVersion4.0.0/modelVersiongroupIdorg.example/groupIdartifactIdmaven_03_pojo/artifactIdpackagingjar/packagingversion1.0-RELEASE/versionnamemaven_03_pojo Maven Webapp/nameurlhttp://maven.apache.org/url!-- 5.配置当前工程继承parent父工程--parentgroupIdorg.example/groupIdartifactIdmaven_01_parent/artifactIdversion1.0-SNAPSHOT/versionrelativePath../maven_01_parent/pom.xml/relativePath/parentdependenciesdependencygroupIdjunit/groupIdartifactIdjunit/artifactIdscopetest/scope/dependency/dependenciesbuildfinalNamemaven_03_pojo/finalName/build
/project