古城堡 发表于 2015-8-6 08:58:33

apache-maven-3.0.4

  apache-maven-3.0.4
  HOW TO ...
  how to setting locale repository
  configure apache-maven-3.0.4\conf\settings.xml
  
C:/maven-repository
  copy the "apache-maven-3.0.4\conf\settings.xml" file to new locale repository "C:\maven-repository".
  Then maven will update locale repository from remote Central Repository.
  The lib download from remote Central Repository will store in C:\maven-repository.
  how to change remote Central Repository address
  configure pom.xml in your project like this.
     
      
            central
            Central Repository
            https://nexus.sourcesense.com/nexus/content/repositories/public/
            default
            
            
                true
            
            
            
                true
            
      
   
  Then new Central Repository address "https://nexus.sourcesense.com/nexus/content/repositories/public/" will replace the dafault Central Repository address configure in "apache-maven-3.0.4\lib\maven-model-builder-3.0.4.jar\org\apache\maven\model\pom-4.0.0.xml".
  
   
      central
      Central Repository
      http://repo.maven.apache.org/maven2
      default
      
      false
      
   

  http://repo.maven.apache.org/maven2 is the default Central Repository address.
  And another way to change central repository configure in "apache-maven-3.0.4\lib\maven-model-builder-3.0.4.jar\org\apache\maven\model\pom-4.0.0.xml" is to configure your locale repository (C:\maven-repository\settings.xml) like this.
  add profile configure to profiles elements and active it.
     
      central-repos
      
      
          central
          Central Repository
          https://nexus.sourcesense.com/nexus/content/repositories/public/
          default
         
         
            true
         
         
         
            true
         
      
      
   



    central-repos

  how to solve dependency conflict
  same dependency path length - first come, first use
  user-core depends on log4j-1.2.16
  user-log depends on log4j-1.29
  user-dao depends on user-core and user-log
  which log4j should user-dao depends on?
  user-core pom.xml
   tos.maven.user
user-core
0.0.1-SNAPSHOT
  
   log4j
   log4j
   1.2.16

  user-log pom.xml
   tos.maven.user
user-log
0.0.1-SNAPSHOT
     
   log4j
   log4j
   1.2.9

  user-dao pom.xml

   tos.maven.user
   user-core
   0.0.1-SNAPSHOT

  
   tos.maven.user
   user-log
   0.0.1-SNAPSHOT

  in pom.xml of user-dao which dependency come first, the corresponding log4j will be used, so user-dao will use log4j-1.2.16.
  different dependency path length - short come, first use
  user-service depends on user-dao and user-dao depends on user-core (which depends on log4j-1.2.16).
  user-service depends on user-log (which depends on log4j-1.2.9).
  then user-service will use log4j-1.2.9 because the length of dependency path is shorter than another (log4j-1.2.16).
  if you want to controll exactly which log4j should be used, you can add exclusions element like this.
  
   tos.maven.user
   user-log
   0.0.1-SNAPSHOT
   
   
   log4j
   log4j
   
   

  then user-service will use log4j-1.2.16.
  if you want to use log4j-1.2.9. you can change pom.xml of use-service like this
  
   tos.maven.user
   user-log
   0.0.1-SNAPSHOT
   
   
   log4j
   log4j
   
   


   tos.maven.user
   user-dao
   0.0.1-SNAPSHOT


   log4j
   log4j
   1.2.9

  because log4j-1.2.9 is the most short dependency path for now.
  how to aggregation mutil project

  aggregation user-core, user-log, user-dao, user-service together.

  4.0.0
tos.maven.user
user-aggregation
0.0.1-SNAPSHOT
pom
   
      ../user-core
      ../user-log
      ../user-dao
      ../user-service
   
  how to extends
  user-parent pom.xml
      tos.maven.user
    user-parent
    0.0.1-SNAPSHOT
    pom
    
      
            
                ..
                ..
                ..
            
      
   
  user-component pom.xml

     
      tos.maven.user
      user-parent
      0.0.1-SNAPSHOT
      ../user-parent/pom.xml
   
     
      
            ..
            ..
      
   
  how to use plugins
  source plugin
  jar-no-fork: package java source file
  configure source plugin in user-parent pom.xml
  the following configuration will binding source plugin goal jar-no-fork to phase package
  

   
   
   org.apache.maven.plugins
   maven-source-plugin
   2.2
   
      
       package
      
      jar-no-fork
      
      
   
   
   


  user-component pom.xml
  

   
    org.apache.maven.plugins
    maven-source-plugin
   


  help plugin
  describe: display help information of special plugin
  The plugin parameter is meant to provide two things: convenience and prefix-based access.
  The convenience comes when specifying a plugin by groupId:artifactId:version. Where the more traditional specification of separate fields would mean specifying this:
  mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-compiler-plugin -Dversion=2.5.1
  the use of the plugin parameter allows this:
  mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin:2.5.1
  On the other hand, the plugin parameter also offers the option to specify a plugin by its prefix, like this:
  mvn help:describe -Dplugin=compiler
  sql plugin
  set properties
  
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/mysql
root
mysqladmin

  configure plugin
     
    org.codehaus.mojo
    sql-maven-plugin
    1.5
   
   
      mysql
      mysql-connector-java
      5.1.21
   
   
   
   ${mysql.driver}
   ${mysql.url}
   ${mysql.username}
   ${mysql.password}
   
      create database if not exists maven_sql_plugin
   
   
   
   
      package
      
       execute
      
   
   
   
  how to deploy your project to tomcat
  setting scope=provided - compile and test will use those jar, but when package your project the jar will not included.
     
    servletapi
    servletapi
    2.4
    provided
   
     
    javax.servlet.jsp
    jsp-api
    2.2
    provided
   
  And use war-plugin and cargo-plugin to deploy to tomcat.
  
页: [1]
查看完整版本: apache-maven-3.0.4