Building complete application folder with maven

前端 未结 1 1944
清酒与你
清酒与你 2021-01-06 10:53

mostly all java standalone-applications end up in a folder looking like this after they are deployed to production.

myapp  
|->lib (here lay all dependenc         


        
相关标签:
1条回答
  • 2021-01-06 11:20

    This kind of deployment directory structure is very popular and have adopted by many brilliant apps like apache maven and ant.

    Yes, we can achieve this by using maven-assembly-plugin at maven package phase.

    Sample 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>
    

    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>
    
    0 讨论(0)
提交回复
热议问题