2012-04-14 1 views
4

ほとんどすべてのJavaスタンドアロンアプリケーションは、本番環境に配備された後、このようなフォルダになります。私のためにその構造を構築し、tar.gz.に入れて達人に何があるかどうか、私は疑問に思う完全なアプリケーションフォルダを構築する

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

Java: How do I build standalone distributions of Maven-based projects?はオプションではありません。私は必要なすべての瓶を開梱するのが大好きではありません。

答えて

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> 

サンプルバイナリの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

関連する問題