4

ほとんどすべての Java スタンドアロン アプリケーションは、本番環境にデプロイされた後、次のようなフォルダーに配置されます。

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

私のためにその構造を構築し、それをtar.gzに入れるMavenに何かがあるのだろうか。

Java: Maven ベースのプロジェクトのスタンドアロン ディストリビューションをビルドするにはどうすればよいですか? オプションはありません。必要なすべてのjarファイルをmavenに解凍させたくありません。

4

1 に答える 1

6

この種の展開ディレクトリ構造は非常に人気があり、apache maven や ant などの多くの優れたアプリで採用されています。

はい、maven パッケージ フェーズで maven-assembly-plugin を使用することでこれを実現できます。

サンプル 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>

サンプル binary-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>
于 2012-04-14T08:32:44.253 に答える