2008-11-27 36 views
1

我有一个多模块maven项目与安装程序子项目。安装程序将作为可执行JAR进行分发。它将设置数据库并将WAR文件解压缩到应用程序服务器。我想用maven来组装这个罐子像这样:插入依赖jar到安装程序jar

/META-INF/MANIFEST.MF
/com/example/installer/Installer.class
/COM /例子/安装/ .. 。
/server.war

清单将有一个主类条目指向安装程序类。我怎样才能让maven以这种方式构建jar?

回答

3

您可以使用Maven Assembly Plugin来构建罐子。

首先,你需要一些信息添加到您的pom.xml 插件部分,使产生的JAR可执行文件:

<plugin> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <configuration> 
    <archive> 
     <manifest> 
     <mainClass>com.example.installer.Installer</mainClass> 
     </manifest> 
    </archive> 
    </configuration> 
</plugin> 


我建议使用一个单独的assembly descriptor构建实际的安装程序罐。这里有一个例子:

<assembly> 
    <id>installer</id> 

    <formats> 
    <format>jar</format> 
    </formats> 

    <baseDirectory></baseDirectory> 

    <dependencySets> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <!-- this references your installer sub-project --> 
     <include>com.example:installer</include> 
     </includes> 
     <!-- must be unpacked inside the installer jar so it can be executed --> 
     <unpack>true</unpack> 
     <scope>runtime</scope> 
    </dependencySet> 
    <dependencySet> 
     <outputDirectory>/</outputDirectory> 
     <includes> 
     <!-- this references your server.war and any other dependencies --> 
     <include>com.example:server</include> 
     </includes> 
     <unpack>false</unpack> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 
</assembly> 


如果您保存了装配描述为“installer.xml”你可以通过运行这样的组件构建的jar:

MVN清洁套装组件:单-Ddescriptor = installer.xml


希望这会有所帮助。以下是你可能会发现一些有用的链接: