Die Lösung mit der Montage-Plugin ein paar Teile hat:
- Das pom das Glas-Plugin (
maven-jar-plugin
) das Konfigurieren und die Konfiguration der Baugruppe Plugin (maven-assembly-plugin
).
- Während der Verpackungsphase von Maven wird das JAR-Plugin aufgerufen, um das Anwendungs-Jar zu konstruieren.
- Dann wird das Assembly-Plug-in ausgeführt und kombiniert das konstruierte JAR, die Ressourcen und die Abhängigkeiten in einer ZIP-Datei, wie von der Assemblydatei definiert (
distribution-zip.xml
).
Im pom, konfigurieren die Plugins:
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<!-- Make an executable jar, adjust classpath entries-->
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>./lib/</classpathPrefix>
<mainClass>com.acme.KillerApp</mainClass>
</manifest>
<!--Resources will be placed under conf/-->
<manifestEntries>
<Class-Path>./conf/</Class-Path>
</manifestEntries>
</archive>
<!--exclude the properties file from the archive-->
<excludes>
<exclude>*.properties</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptors>
<descriptor>${basedir}/assembly/distribution-zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
...
Der Inhalt der Baugruppendatei distribution-zip.xml
(mit dank Neeme Praks) kombiniert die erzeugten Glas, Ressourcen und Abhängigkeiten:
<assembly>
<id>dist</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<!--Include runtime dependencies-->
<outputDirectory>lib</outputDirectory>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<!--Get the generated application jar-->
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
<fileSet>
<!--Get application resources-->
<directory>src/main/resources</directory>
<outputDirectory>conf</outputDirectory>
</fileSet>
<fileSet>
<!--Get misc user files-->
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Die resultierende verteilbare Zip-Datei wird erstellt wie target/killer-app-1.0-dist.zip
!
Cool, aber auch, um das jar ausführbar zu machen, legen Sie den Manifest Klassenpfad, und schließen Sie die Eigenschaftendatei aus dem jar .. – brasskazoo
, das ist bereits eine Frage der Konfiguration Ihres JAR-Plugin, nichts mit Assembly-Plugin zu tun. Ich schätze, du machst das schon, nein? Und es wäre hilfreich, wenn Sie relevante Abschnitte aus Ihrer pom.xml zu Ihrer Frage hinzufügen würden. –
mache JAR ausführbar und setze manifest classpath: http://maven.apache.org/shared/maven-archiver/examples/claspath.html, Eigenschaften ausschließen: http://maven.apache.org/plugins/maven-jar- plugin/usage.html –