maven is life-cycle based project build, deploy and management tools.After you download and install maven fromApachesite, 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'sclass-loaderandXMLparser tools.According to m2.conf, plexusclass-worldlaunchesorg.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 andMavenExecutionRequest 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.
- RegisterEventDispatcher and Monitor;
- Parse pom XML file usingorg.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 callDefaultLifecycleExecutor 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 );
Maven项目构建流程解析
本文介绍了Maven作为基于生命周期的项目构建、部署和管理工具的工作原理。详细讲解了Maven如何通过plexus核心库加载类及配置,解析命令行参数,并通过MavenCli类执行项目的构建过程。

被折叠的 条评论
为什么被折叠?



