标签:
任何一个构件都有其唯一的坐标,根据这个坐标可以定义其在仓库中的唯一存储路径,这便是Maven的仓库布局方式。例如log4j:log4j:1.2.15这一依赖,其对应的仓库路径为log4j/log4j/1.2.15/log4j-1.2.15.jar,该路径与坐标的大致对应关系为groupId/artifactId/version/artifactId-version.packaging。下面看一段Maven的源码并结合具体的实例来理解Maven仓库的布局方式
private static final char PATH_SEPARATOR = ‘/‘; private static final char GROUP_SEPARATOR = ‘.‘; private static final char ARTIFACT_SEPARATOR = ‘-‘; public String pathOf( Artifact artifact ) { ArtifactHandler artifactHandler = artifact.getArtifactHandler(); StringBuilder path = new StringBuilder( 128 ); path.append( formatAsDirectory( artifact.getGroupId() ) ).append( PATH_SEPARATOR ); path.append( artifact.getArtifactId() ).append( PATH_SEPARATOR ); path.append( artifact.getBaseVersion() ).append( PATH_SEPARATOR ); path.append( artifact.getArtifactId() ).append( ARTIFACT_SEPARATOR ).append( artifact.getVersion() ); if ( artifact.hasClassifier() ) { path.append( ARTIFACT_SEPARATOR ).append( artifact.getClassifier() ); } if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 ) { path.append( GROUP_SEPARATOR ).append( artifactHandler.getExtension() ); } return path.toString(); } private String formatAsDirectory( String directory ) { return directory.replace( GROUP_SEPARATOR, PATH_SEPARATOR ); }
该pathOf()方法的目的是根据构件信息生成其在仓库中的路径。这里,我们根据一个实际的例子来分析路径的生成,考虑这样一个构件:groupId=org.testng、artifactId=testng、version=5.8、classifier=jdk15、packaging=jar,其对应的路径按如下步骤生成:
摘自:http://juvenshun.iteye.com/blog/547787
标签:
原文地址:http://www.cnblogs.com/geekdc/p/5867400.html