用Maven构建完整的应用程序文件夹 [英] Building complete application folder with maven
问题描述
主要是所有Java独立的应用程序看起来像这样的文件夹中结束了,他们被部署到生产之后。
mostly all java standalone-applications end up in a folder looking like this after they are deployed to production.
myapp
|->lib (here lay all dependencies)
|->config (here lay all the config-files)
|->myapp.bat
|->myapp.sh
我不知道是否有Maven中任何与构建一个结构,我并把它放在一个tar.gz。
I wonder if there is anything in maven with builds that structure for me and put it in a tar.gz.
<一个href=\"http://stackoverflow.com/questions/1015520/java-how-do-i-build-standalone-distributions-of-maven-based-projects\">Java:如何构建基于Maven的项目独立分布?是没办法。我不想Maven来解开我需要的所有jar文件。
Java: How do I build standalone distributions of Maven-based projects? is no option. I dont want maven to unpack all the jars I need.
推荐答案
这种部署目录结构中很受欢迎,并已被许多辉煌的应用程序,如Apache Maven和蚂蚁采用。
This kind of deployment directory structure is very popular and have adopted by many brilliant apps like apache maven and ant.
是的,我们可以通过使用maven-组装插件在Maven的包装阶段实现这一目标。
Yes, we can achieve this by using maven-assembly-plugin at maven package phase.
样的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中:
Sample 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>
这篇关于用Maven构建完整的应用程序文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!