2008-11-12 6 views
8

Załóżmy, że mam następujący układ katalogów w projekcie Maven:Jak mogę zainstalować aplikację konsolową z Mavenem bez rozpakowywania wszystkich zależności?

src/ 
|-- main 
| |-- bin 
| | |-- run.cmd 
| | `-- run.sh 
| |-- etc 
| | |-- common-spring.xml 
| | |-- log4j.xml 
| | `-- xml-spring.xml 
| `-- java 
|  `-- com 
... 

chciałbym zbudować plik zip, że po rozpakowaniu, produkuje coś takiego:

assembly 
|-- bin 
| |-- run.cmd 
| `-- run.sh 
|-- etc 
| |-- common-spring.xml 
| |-- log4j.xml 
| `-- xml-spring.xml 
`-- lib 
    |-- dependency1.jar 
    |-- dependency2.jar 
... 

gdzie `run. xx 'to wykonywalne skrypty powłoki, które będą wywoływać moją główną aplikację i umieścić wszystkie zależności w ścieżce klasy.

Jest to możliwe w przypadku niektórych "oficjalnych" wtyczek Mavena, np. maven-assembly-plugin?

Odpowiedz

11

Używam AppAssembler plugin, aby uzyskać coś podobnego. Przykład:

... 
<build> 
<plugins> 
    <plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>appassembler-maven-plugin</artifactId> 
    <configuration> 
     <programs> 
     <program> 
      <mainClass>com.acme.MainClass</mainClass> 
      <name>app</name> 
     </program> 
     </programs> 
    </configuration> 
    </plugin> 
</plugins> 

-1

appassembler generuje pliki 'run.xx' dla Ciebie.

Jeśli samodzielnie utworzyłeś już skrypty powłoki, możesz użyć pliku maven-assembly-plugin, aby utworzyć plik zip. Aby zebrać zależności, można użyć wtyczki zależnej od maven.

1

maven montaż plugin można również skopiować zależności do swojego zespołu, o tym coś jak poniżej w pliku deskryptora montażowej:

<dependencySets> 
    <!-- Copy dependency jar files to 'lib' --> 
    <dependencySet> 
     <outputDirectory>lib</outputDirectory> 
     <includes> 
      <include>*:jar:*</include> 
     </includes> 
    </dependencySet> 
</dependencySets> 
5

Użyłem maven montaż plugin do acheive coś podobnego w projekcie. Chciałem, aby plik zip był budowany podczas fazy pakietowej zamiast ręcznego wywoływania zestawu: montaż. Oto co wymyśliłem:

/src/assemble/distribution.xml:

<assembly> 
    <id>distribution</id> 

    <!-- specify the output formats --> 
    <formats> 
    <format>zip</format> 
    </formats> 

    <!-- include all runtime libraries in the /lib folder of the output file --> 
    <dependencySets> 
    <dependencySet> 
     <outputDirectory>/lib</outputDirectory> 
     <scope>runtime</scope> 
    </dependencySet> 
    </dependencySets> 

    <fileSets> 
    <!-- include all *.jar files in the target directory --> 
    <fileSet> 
     <directory>target</directory> 
     <outputDirectory></outputDirectory> 
     <includes> 
     <include>*.jar</include> 
     </includes> 
    </fileSet> 

    <!-- include all files in the /conf directory --> 
    <fileSet> 
     <outputDirectory></outputDirectory> 
     <includes> 
     <include>conf/**</include> 
     </includes> 
    </fileSet> 
    </fileSets> 

</assembly> 

/pom.xml

...

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 

      <configuration> 
       <descriptors> 
        <descriptor>src/assemble/distribution.xml 
        </descriptor> 
       </descriptors> 
      </configuration> 

      <!-- append assembly:assembly to the package phase --> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>assembly</goal> 
        </goals> 
       </execution> 
      </executions> 

     </plugin> 

...

+0

Czy ten zestaw może zostać automatycznie wdrożony przy wdrożeniu mvn? –

Powiązane problemy