Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I put application configuration files for a Maven project?

Tags:

maven-2

spring

I'm using the Maven Application Assembler plugin to generate stand-alone executables from my Java project. The application reads in configuration files, including Spring files. The Application Assembler plugin has an option (activated by default) to add a etc/ directory to the application's classpath, but what should I do to have the plugin copy my configuration files to this directory?

Or more generally, where is in Maven the kosher location for application configuration files that should NOT be packaged in the artifact?

like image 726
lindelof Avatar asked Jan 21 '09 11:01

lindelof


People also ask

Where do configurations go in pom files?

src/main/resources/conf/default. xml. src/main/conf/default. xml.

Where should config files be stored?

These config files are typically placed under separate root directory than the rest of application code. For example, in case of Java they are typically under src/main/resources .

Which one is the configuration file for a Maven project?

The POM. The pom. xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want.

Where is Maven configuration file?

The Maven settings file, settings. xml , is usually kept in the . m2 directory inside your home directory.


2 Answers

For folks who have come to this more recently there is, since version 1.1 of the Application Assembler Plugin, the optional parameters configurationSourceDirectory and copyConfigurationDirectory. Please find them in an example POM.xml extract below:

<configuration>
  <!-- Set the target configuration directory to be used in the bin scripts -->
  <configurationDirectory>conf</configurationDirectory>
  <!-- Copy the contents from "/src/main/config" to the target
      configuration directory in the assembled application -->
  <copyConfigurationDirectory>true</copyConfigurationDirectory>
  <!-- Include the target configuration directory in the beginning of
      the classpath declaration in the bin scripts -->
  <includeConfigurationDirectoryInClasspath>
    true
  </includeConfigurationDirectoryInClasspath>
...
</configuration>

More information is here

like image 152
Glenn Lawrence Avatar answered Sep 30 '22 16:09

Glenn Lawrence


You can also use resource filtering: http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files

turn on filtering:

...
<build>
...
<resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
...
</build>
...

make a file under src/main/resources like: application.properties

application.properties

configprop.1=${param1}
configprop.2=${param2}

Then setup a profile and set some properties perhaps in a settings.xml that sets different properties depending on if this is a dev or production build. see: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

I have different properties set depending on if this is the build server, dev or a production deployment

mvn -Denv=dev || mvn -Denv=dev-build || mvn -Denv=production

The maven link has a pretty good description.

like image 32
Nathan Feger Avatar answered Sep 30 '22 15:09

Nathan Feger