zoukankan      html  css  js  c++  java
  • maven

    1. 默认情况下,java源码应该放在src/main/java/……目录下,测试源码应该放在src/main/test/……目录下
    2. mvn clean compile生成.class文件,mvn clean install生成.class文件和.jar文件
    3. 当仓库里不存在pom文件中的依赖时,第一次会报这样的错误:
      [ERROR] Failed to execute goal on project hello: Could not resolve dependencies for project com.cisco.mytest:hello:jar:1.0.0-SNAPSHOT: Could not find artifact junit:junit:jar:4.13 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
      然后在~/.m2/repository本地仓库中会有两个文件:***.jar.lastUpdated***.pom.lastUpdated
      当再次运行mvn时,会报这样的错误:
      [ERROR] Failed to execute goal on project hello: Could not resolve dependencies for project com.cisco.mytest:hello:jar:1.0.0-SNAPSHOT: Failure to find junit:junit:jar:4.13 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
    4. mvn clean compile(会生成.class文件)
      mvn clean test(会执行src目录下的test文件夹里的内容,执行之前会执行compile)
      mvn clean package(会生成.jar文件,在执行之前会执行test)
      mvn clean install(会将.jar文件安装到~/.m2/repository,在执行之前会执行package)
      5.如果在java源码中加入包信息语句package com.cisco.mytest.hello;,那么在target目录下就会生成带有相同目录结构的文件夹com/cisco/mytest/hello和class文件,如果不加包信息,则不生成上述文件夹,只有class文件
      6.在java源码中加入包信息语句package com.cisco.mytest.hello;,那么我在class目录下运行java HelloWorld会提示错误: 找不到或无法加载主类 HelloWorld。应该在src/main/java目录下运行java com.cisco.mytest.hello.HelloWorld,在合适的目录下,运行带有包信息的命令
    5. 仓库路径与坐标的关系为:groupId/artifactId/version/artifactId-version.packaging,例如依赖org.sonatype.nexus:nexus-indexer:2.0.0,其对应的路径为org/sonatype/nexus/nexus-indexer/2.0.0/nexus-indexer-2.0.0.jar,jar包文件名的格式为artifactId-version.packaging,所以artifactId应该使用实际项目名作为前缀,比如nexus-indexer
    6. 聚合模块:聚合模块是顶层模块,在其POM文件中,<packaging>应该为pom(默认为jar),无<dependency>,子模块写在<module>中,<module>中的子模块名字必须与其目录文件名一致,所以子模块目录文件名应该与artifactId一致,这样<module>就与artifactId一致了
    7. 继承模块:其POM文件中的<packaging>也为pom、
    8. 一般都将继承模块和聚合模块放在一起融合使用
    9. dependencies与 dependencyManagement的区别:

      dependencies作为父项目:即使在子项目中不写该依赖项,那么子项目仍然会从父项目中继承该依赖项(全部继承)

      dependencyManagement作为父项目:只声明依赖,并不实现引入。具体的引入由子项目根据需要完成,子项目不声明,就不会引入依赖。只有在子项目中写了该依赖项,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;如果子项目中指定了版本号,那么会使用子项目中指定的版本。

  • 相关阅读:
    hashMap put的返回值测试
    mysql java 类型对照 int
    crontab
    Caused by: java.lang.IllegalArgumentException: Modifying queries can only use void or int/Integer as return type!
    Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean
    Spring boot ---- java.lang.NoClassDefFoundError: javax/servlet/ServletContext
    蒙特卡罗算法:模拟
    Linux学习笔记:cut命令
    Linux学习笔记:split切分文件并按规律命名及添加拓展名
    Shell学习笔记:awk实现group by分组统计功能
  • 原文地址:https://www.cnblogs.com/season-peng/p/6713486.html
Copyright © 2011-2022 走看看