[Maven] Explore maven code by code

maven is life-cycle based project build, deploy and management tools.After you download and install maven from Apache site, you use mvn plus option commands to manage your projects. In fact, following code is executed in linux system.

exec "$JAVACMD" \
  $MAVEN_OPTS \
  -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
  "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
  "-Dmaven.home=${M2_HOME}"  \
  ${CLASSWORLDS_LAUNCHER} "$@"
In maven, plexus project from codehaus is depended library. maven makes use of plexus's class-loader and XML parser tools.According to m2.conf, plexus class-world launches org.apache.maven.cli.MavenCli to do the whole work.

main is org.apache.maven.cli.MavenCli from plexus.core

set maven.home default ${user.home}/m2

[plexus.core]
optionally ${maven.home}/lib/ext/*.jar
load       ${maven.home}/lib/*.jar
MavenCli is an important class as it is the entry point for maven world. This class takes advantage of Apache common command line package and parse the argument from $@ into CommandLine object.

public class MavenCli {

public static int main( String  [] args, ClassWorld classWorld ){
 CLIManager cliManager = new CLIManager();
 CommandLine commandLine;
 commandLine = cliManager.parse( args );
}

}

After that, setting related to build are build up and MavenExecutionRequest and Maven instance are created. MavenExecutionRequest object is common java bean or JOPO which holds the information about the project like pom file name, ArtifactRepository, Goals and etc. class Maven is the man who carries out the build work further.

maven = createMavenInstance( settings.isInteractiveMode() );
maven.execute( request );
Maven class is glanced as below and some features are worthy of being highlighted.

  • Register EventDispatcher and Monitor;
  • Parse pom XML file using org.codehaus.plexus.util.xml.Xpp3Dom;
  • Use data from pom XML file to fill into Project and Model,Repository, Extension, Plugin objects;
  • Loop each project and call DefaultLifecycleExecutor to run each project.   
List   projects = getProjects( request, globalProfileManager );
rm = new ReactorManager( projects );
MavenSession session = createSession( request, rm );
session.setUsingPOMsFromFilesystem( foundProjects );
lifecycleExecutor.execute( session, rm, dispatcher );

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值