发表于: 2018-04-03 22:24:01

1 761


今天完成的事情:

        1.解决昨天对依赖范围的疑惑,用Maven构建一个java web项目,和创建java项目大部分相同.但是原型要选maven-archetype-webapp

   mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-WebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false


        2.clean/install

          1.clean

            执行mvn  -clean后my-app下的target文件夹被清除

                  

            2.如果执行了install命令,本地仓库还是可以找到的.clean不影响install

                    


明天计划的事情

        整理一下这几天的资料,看一下之前建的数据库有没有什么可以优化的地方,然后继续走任务流程.   

遇到的问题:

       <project> 

       <modelVersion>4.0.0</modelVersion> 

       <groupId>maven</groupId> 

       <artifactId>B</artifactId> 

       <packaging>pom</packaging> 

       <name>B</name>

       <version>1.0</version> 

       <dependencyManagement>  

            <dependencies>    

                <dependency>       

                     <groupId>maven</groupId>     

                     <artifactId>A</artifactId>    

                     <version>1.0</version>  

                     <type>pom</type>     

                     <scope>import</scope>    

                </dependency> 

                <dependency                  

                     <groupId>maven</groupId>     

                     <artifactId>C</artifactId>    

                     <version>1.0</version>  

                </dependency> 

             </dependencies> 

       </dependencyManagement>

   </project>     

      A,B,C三者的关系,我的理解是.B导入了A的构建,依赖C这个项目,感觉光看理论知识太晕了.明天整理下这几天的笔记,然后如果时间够,开始往下做任务吧

收获:

       参考:https://blog.csdn.net/u012814506/article/details/47355647,

       Maven在编译项目主代码的时候需要使用一套classpath,在执行测试的时候会使用另外一套classpath,在实际运行Maven项目的时候,会使用使用一套classpath.所以scope是决定在哪个阶段会引入哪个构件

       compile:编译依赖范围,也是缺省值--有些依赖在主代码中需要import,在测试代码中也需要import,打包的时候还需要一起打包上传服务器,则scope是compile。

       test:测试依赖范围,只有在使用Maven执行测试的时候才会引用该构件--有些代码是测试需要import,而主代码中不需要,我们不需要把junit打包上传到服务器,则scope是test

       provide:已提供依赖范围,编译和测试时引用该构件,但是在运行时候无效--以servlet-api为例,tomcat中已经提供了servlet-api的jar包,但是本地写代码的时候,只需要import进去,而不需要把servlet-api的jar包打包到服务器上,如果打包了,可能会产生jar包冲突,这个时候用provided。

       runtime:运行时依赖范围,测试和运行项目时引入构件,在编译主代码是无效--mysql的jdbc驱动,在本地写代码的时候,我们都是引入的jdbc接口,并不需要引入具体的jdbc驱动实现,所以写代码的时候并不需要,而运行的时候,我们需要使用具体的驱动,这样的jar包我们的scope为runtime。

       import:导入依赖范围.在编译项目主代码,测试和运行的时候都不会引入该构件.只在使用dependencyManagement中,表示从其他pom中导入dependecy的配置.官网原文--This scope is only supported on a dependency of type pom in the section. It indicates the dependency to be replaced with the effective list of dependencies in the specified POM’s section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

       system:系统依赖范围.和provide效果一样,但是使用system范围的依赖必须通过systemPath元素显示指定依赖文件的路径.不会在Maven存储库中查找.systemPath元素可以使用环境变量,如:

      <dependecy>

             <groupId>java.sql</groupId>

             <artifavtId> jdbc-stdext</artifactId>

             <version>2.0</version>

             <scope>system</scope>

             <systemPath> ${java.home}/lib/rt.jar</systemPath>

      </dependecy>


返回列表 返回列表
评论

    分享到