2012-04-14 125 views
4

大多数所有java standalone应用程序在部署到生产环境后都会以文件夹的形式显示。使用maven构建完整的应用程序文件夹

myapp 
|->lib (here lay all dependencies) 
|->config (here lay all the config-files) 
|->myapp.bat 
|->myapp.sh 

我不知道是否有maven中的任何东西与我的结构,并把它放在一个tar.gz.

Java: How do I build standalone distributions of Maven-based projects?没有选项。我不想Maven解开所有我需要的罐子。

回答

6

这种部署目录结构中非常流行,而且已经通过了无数辉煌的应用程序,如Apache Maven和蚂蚁采用。

是的,我们可以通过使用maven具组件插件在Maven的封装阶段实现这一目标。

样品的pom.xml:

<!-- Pack executable jar, dependencies and other resource into tar.gz --> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.2-beta-5</version> 
    <executions> 
     <execution> 
     <phase>package</phase> 
     <goals><goal>attached</goal></goals> 
     </execution> 
    </executions> 
    <configuration> 
     <descriptors> 
     <descriptor>src/main/assembly/binary-deployment.xml</descriptor> 
     </descriptors> 
    </configuration> 
    </plugin> 

样品二进制deployment.xml中:

<!-- 
    release package directory structure: 
    *.tar.gz 
     conf 
     *.xml 
     *.properties 
     lib 
     application jar 
     third party jar dependencies 
     run.sh 
     run.bat 
--> 
<assembly> 
    <id>bin</id> 
    <formats> 
    <format>tar.gz</format> 
    </formats> 
    <includeBaseDirectory>true</includeBaseDirectory> 
    <fileSets> 
    <fileSet> 
     <directory>src/main/java</directory> 
     <outputDirectory>conf</outputDirectory> 
     <includes> 
     <include>*.xml</include> 
     <include>*.properties</include> 
     </includes> 
    </fileSet> 
    <fileSet> 
     <directory>src/main/bin</directory> 
     <outputDirectory></outputDirectory> 
     <filtered>true</filtered> 
     <fileMode>755</fileMode> 
    </fileSet> 
    <fileSet> 
     <directory>src/main/doc</directory> 
     <outputDirectory>doc</outputDirectory> 
     <filtered>true</filtered> 
    </fileSet> 
    </fileSets> 
    <dependencySets> 
    <dependencySet> 
     <outputDirectory>lib</outputDirectory> 
     <useProjectArtifact>true</useProjectArtifact> 
     <unpack>false</unpack> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 
</assembly> 
+0

看起来不错,谢谢你 – mibutec 2012-04-14 15:07:18

相关问题