从第36行可以看出,在最终创建archiver时候(createArchiver方法),它会吧assembly.isIncludeBaseDirectory()作为参数传递进去,我们看下如果这个参数设置为false的行为。
protected Archiver createArchiver( final String format, final boolean includeBaseDir, final String finalName, final AssemblerConfigurationSource configSource, final List<ContainerDescriptorHandler> containerHandlers ) throws ArchiverException, NoSuchArchiverException { Archiver archiver; if ( format.startsWith( "tar" ) ) { archiver = createTarArchiver( format, configSource.getTarLongFileMode() ); } else if ( "war".equals( format ) ) { archiver = createWarArchiver(); } else { archiver = archiverManager.getArchiver( format ); } final List<FileSelector> extraSelectors = new ArrayList<FileSelector>(); final List<ArchiveFinalizer> extraFinalizers = new ArrayList<ArchiveFinalizer>(); if ( archiver instanceof JarArchiver ) { extraSelectors.add( new JarSecurityFileSelector() ); extraFinalizers.add( new ManifestCreationFinalizer( configSource.getProject(), configSource.getJarArchiveConfiguration() ) ); } if ( configSource.getArchiverConfig() != null ) { configureArchiver( archiver, configSource ); } String prefix = ""; if ( includeBaseDir ) { prefix = finalName; } archiver = new AssemblyProxyArchiver( prefix, archiver, containerHandlers, extraSelectors, extraFinalizers, configSource.getWorkingDirectory(), getLogger(), configSource.isDryRun() ); archiver.setUseJvmChmod( configSource.isUpdateOnly() ); archiver.setIgnorePermissions( configSource.isIgnorePermissions() ); archiver.setForced( !configSource.isUpdateOnly() ); return archiver; }
这里,从36到40行可以看出来,当includeBaseDirectory为true时候,prefix为artifact的finalName,如果为false,则设置为"",而这个finalName就是分发包的最外层。所以,当我们吧includeBaseDirectory设置为false,就没有包装层了。这个结果正和官网上对这个参数的说明一致。具体打包过程见AssemblyProxyArchiver,我就不展开了。
原文地址:http://www.bianceng.cn/a/2013/1123/38345_3.htm