tags:

views:

1427

answers:

3

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?

+1  A: 

Hi,

I don't know if I understand you correctly. But what I have done in the past for a project where I needed to copy configuration files, is use the Maven AntRun plugin. What I did is execute the plugin in the process-resources phase and copied my configuration files to the specified directory using the Ant copy task. The Assembler plugin executes in the package phase so it should pick up your configuration files if you put it in the right place. Hope this answers your question a little bit.

Taner Gedikoğlu
Yes I figure that would be the easiest way to do this manually. I just wondered whether the appassembler plugin could do this for you, i.e. pick up config files from, say, src/etc and copy them over to ${appname}/etc.
lindelof
A: 

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.

Nathan Feger
+2  A: 

You could try the maven assembly plugin. I used it in conjunction with the appassembler plugin.

Configure appassembler to point to whatever name you want for your configuration directory, if you don't want 'etc'. The assembly plugin assembles everything in its own output directory, so I configure the assembly plugin to copy the bin and repo dirs from the appassembler directory into its output dir, then I have it copy the config files (mine are in src/main/config) into the expected config dir. There is some duplication in this, because you are copying the appassembler outputs, but that didn't really bother me.

So what you have after executing the assembly plugin is your bin, repo, and config dir are all peer directories under the assembly output directory. You can configure it to have a different structure if you prefer, I just wanted mine to mirror the appassembler structure.

The nice thing is that you can also configure the assembly plugin to change your binaries to executables, which I could't see how to do with appassembler. And, if you then bind appassembler:assemble and assembly:single goals to the package phase, all you have to do is 'mvn package', and it assembles everything.

Missy Petty