首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用maven构建完整的应用程序文件夹

用maven构建完整的应用程序文件夹
EN

Stack Overflow用户
提问于 2012-04-14 14:08:36
回答 1查看 415关注 0票数 4

大多数情况下,所有的java单机版应用程序在部署到生产环境后,最终都会出现如下所示的文件夹。

代码语言:javascript
复制
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打开我需要的所有罐子。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-14 16:32:44

这种部署目录结构非常流行,并已被许多优秀的应用程序采用,如apache maven和ant。

是的,我们可以通过在maven包阶段使用maven-assembly-plugin来实现。

示例pom.xml:

代码语言:javascript
复制
  <!-- 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:

代码语言:javascript
复制
<!--
  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>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10151458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档