Maven file filtering
Warning: Do not filter files with binary content like images! This will most likely result in corrupt output. If you have both text files and binary files as resources it is recommended to have two separated folders. In this tutorial I'll explain how to deal with multiple deployment environments such as development and production from a configuration perspective. Specifically I'll show how environment-specific configurations, such as database connections and resource contents, can be "managed" in a centralized way by the developer.
This tutorial assumes some working knowledge of Maven overlays. The Using Maven overlays to build customized applications tutorial is a good starting point, which also introduces the Portofino example that we'll expand and refine here. If you're impatient and a bit of a Maven expert you can jump to the section "Putting it all together: the pom. Maven profiles allow a parametrization of the build process with the purpose of making the target application portable across several deployment environments.
A profile is the centralized place where you can define build parameters that apply only to certain environments but not to others. In our case the database connection details are environment-specific. We'll have a "development" profile customized to the needs of a development environment webapp and database running on "localhost", e.
Also we want the application logo to be different for the two environments. Profiles can be activated automatically, e. We'll work with the latter situation. Profiles can be specified in the pom. They can also be specified in user-specific files, outside the project directory structure.
More details can be found in Maven's official introduction to build profiles. For simplicity in our examples we'll define profiles inside the main pom. This process is called filtering. Filtering is dsiable by default. To enable it, you must modify the filtering element of the Pom.
To reference a property from the configuration files, the property name uses the following syntax:. Filtering resources can also get values from system properties built into Java like:. Configures a filter for files headed into the assembly archive, to enable aggregation of various types of descriptor fragments, such as components.
Contains configuration options for including the source files of a project module in an assembly. Contains configuration options for including the binary files of a project module in an assembly. Since 2. A file allows individual file inclusion with the option to change the destination filename not supported by fileSets.
Note: either source or sources is required. Defines a Maven repository to be included in the assembly. The artifacts available to be included in a repository are your project's dependency artifacts. The repository created contains the needed metadata entries and also contains both sha1 and md5 checksums.
This is useful for creating archives which will be deployed to internal repositories. NOTE: Currently, only artifacts from the central repository are allowed. Assembly Maven Assembly Plugin relies on the provided assembly descriptors to dictate its execution. Element Type Description id String Sets the id of this assembly.
This is a symbolic name for a particular assembly of files from this project. Also, aside from being used to distinctly name the assembled package by attaching its value to the generated archive, the id is used as your artifact's classifier when deploying. It is often better to specify the formats via the goal parameter rather than here.
For example, that allows different profiles to generate different types of archives. Multiple formats can be supplied and the Assembly Plugin will generate an archive for each of the desired formats.
When deploying your project, all file formats specified will also be deployed. For example, if you are creating an assembly named "your-app", setting includeBaseDirectory to true will create an archive that includes this base directory. If this option is set to false the archive created will unzip its content to the current directory.
Default value is : true. The site directory location of a project is determined by the siteDirectory parameter of the Assembly Plugin. Default value is : false.
The locations specified must be relative to the base location of the descriptor. When multiple componentDescriptors are found, their contents are merged. Check out the descriptor components for more information. Element Type Description handlerName String The handler's plexus role-hint, for lookup from the container.
0コメント