Правдиво, это довольно существенная сборка, и есть некоторые лучшие практики, которые я использую, чтобы держать все эти вещи организовано.
Во-первых, я хотел бы разделить свой код на несколько модулей, и положи его следующим образом:
pom.xml
/src
/app
/app-name
pom.xml
/src ...
/app-name-sdk
pom.xml
/src ...
/deployment
pom.xml
/src
/assembly
image.xml
/main
/app-folder
/bin
startup-script.sh
startup-script.bat
/etc
config.conf
...
/plugins
/plugin-A
pom.xml
/src ...
/plugin-B
pom.xml
/src ...
An это точка, вы логически разделены все различные составные части, в результате чего ясно, где все , упаковывается в логические группы. (Теперь, когда я проверяю это снова, он не похож на папку vomit, так как теперь я могу хранить директории/doc и/bin на верхнем уровне и знать, что подкаталоги в/src описывают, что находится в каждом ассоциированном подмодуле.)
в этот момент верхний pom.xml уровень должен выглядеть примерно так:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>app-name-parent</artifactId>
<groupId>com.mycompany.my-app</groupId>
<version>1.3.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>[Parent] My App</name>
<modules>
<!-- App -->
<module>src/app/app-name</module>
<module>src/app/my-app-sdk</module>
<!-- Plugins -->
<module>src/plugins/plugin-A</module>
<module>src/plugins/plugin-B</module>
<!-- Packaging -->
<module>src/app/distribution</module>
</modules>
<properties>
<!-- Useful properties to define here -->
<scm.revision>USER</scm.revision>
<compiler.debug>true</compiler.debug>
<compiler.optimize>false</compiler.optimize>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- If you're not going to version your plugins with the parent,
then you should pick out the specific version info here
for each plugin. That way, you could just update individual plugins.
If this is to be packaged up and shipped together, it's probably not necessary.
-->
<plugin-A.version>1.1</plugin-A.version>
<plugin-B.version>1.3</plugin-B.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<debug>${compiler.debug}</debug>
<optimize>${compiler.optimize}</optimize>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencyManagement>
<dependencies>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<profiles>
<profile>
<id>release</id>
<properties>
<compiler.debug>false</compiler.debug>
<compiler.optimize>true</compiler.optimize>
</properties>
</profile>
<profile>
<id>ci-server</id>
<activation>
<property>
<name>env.SVN_REVISION</name>
</property>
</activation>
<properties>
<scm.revision>${env.SVN_REVISION}</scm.revision>
</properties>
</profile>
</profiles>
</project>
Тогда все из дочерних модулей требуется определить ссылку на родителя, например, так:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app-name-parent</artifactId>
<groupId>com.mycompany.my-app</groupId>
<version>1.3.2-SNAPSHOT</version>
<relativePath>../../..</relativePath>
</parent>
<groupId>com.mycompany.my-app</groupId>
<artifactId>app-name</artifactId>
<name>[App] My App</name>
<description>
TODO
</description>
<dependencies>
<!-- System dependencies -->
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>app-name-sdk</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Для любви ко всему, что свято и право в этом мире, сделайте не попробуйте упаковать все в одном из модулей, связанных с выводом банок. Это неправильно, и все, кто это делает, это shunt.
Я шучу.
Но серьезно: вывести процесс упаковки в отдельный модуль, здесь модуль src/app/deployment
для упаковки других артефактов сборки. Тогда он действительно только зависит от других компонентов в системе, и может выглядеть примерно так:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>app-name-parent</artifactId>
<groupId>com.mycompany.my-app</groupId>
<version>1.3.2-SNAPSHOT</version>
<relativePath>../../..</relativePath>
</parent>
<groupId>com.mycompany.my-app</groupId>
<artifactId>deployment</artifactId>
<packaging>pom</packaging>
<name>[App] Deployment Image</name>
<description>
TODO
</description>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>image</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<tarLongFileMode>gnu</tarLongFileMode>
<descriptors>
<descriptor>src/assembly/image.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>my-app</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<!-- Notice the separate group namespace element 'plugins', for clarity -->
<groupId>${project.parent.groupId}.plugins</groupId>
<artifactId>plugin-A</artifactId><!-- Or project.version, depending... -->
<version>${plugin-A.version}</version>
</dependency>
<dependency>
<groupId>${project.parent.groupId}.plugins</groupId>
<artifactId>plugin-B</artifactId>
<version>${plugin-B.version}</version><!-- Or project.version, depending... -->
</dependency>
</dependencies>
</project>
Затем вы можете использовать дескриптор файла сборки (здесь, image.xml), чтобы упаковать все в единое целое , например, так:
<assembly>
<id>image</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!-- Everything -->
<dependencySet>
<outputDirectory>/app-folder/jars</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<fileMode>0644</fileMode>
<directoryMode>0644</directoryMode>
<!-- This includes all transitive, <scope>compile</scope> dependencies -->
<includes>
<include>${project.parent.groupId}:*</include>
</includes>
</dependencySet>
</dependencySets>
<!-- Packaged scripts, config files, etc. -->
<fileSets>
<fileSet>
<outputDirectory>/app-folder/bin</outputDirectory>
<lineEnding>unix</lineEnding>
<fileMode>0755</fileMode>
<directoryMode>0744</directoryMode>
<filtered>false</filtered>
<directory>src/main/app-folder/bin</directory>
<includes>
<include>**/*</include>
</includes>
<!-- Some weird files are added here, for some reason -->
<excludes>
<exclude>*.*.formatted</exclude>
</excludes>
</fileSet>
<fileSet>
<outputDirectory>/app-folder/etc</outputDirectory>
<lineEnding>unix</lineEnding>
<fileMode>0640</fileMode>
<directoryMode>0744</directoryMode>
<filtered>true</filtered>
<directory>src/main/app-folder/etc</directory>
<includes>
<include>**/*</include>
</includes>
<!-- Some weird files are added here, for some reason -->
<excludes>
<exclude>*.*.formatted</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
Вы можете получить много любителя с упаковкой, но это голые кости, что получает вас 90% пути там.
Прошу прощения за это, но я делаю это много, и после этого практика действительно делает все намного более чистым и понятным, особенно если мне придется вернуться к нему через несколько месяцев после этого.
Я думаю, что это то, что я ищу ... действительно, это не веб-приложение - это настольное приложение и будет распространяться как таковое ... – helifreak