My recent project was aimed to develop standalone application written in Swing with embedded database which was in form of JSON file. During building my Jar using Maven, I was faced with problem to replace this JSON file before final application will be produced. Before you will prepare such solution you should get familiar with Maven Build Lifecycle [1]. Below I listed those LifeCycle's :
- validate
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
- process-classes
- generate-test-sources
- process-test-sources
- generate-test-resources
- process-test-resources
- test-compile
- test
- prepare-package (maven 2.1+)
- package
- pre-integration-test
- integration-test
- post-integration-test
- verify
- install
- deploy
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>fetchJSON</id>
<phase>prepare-package</phase>
<inherited>false</inherited>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>pl.avantis.iom.rest.DrupalQueriesImpl</mainClass>
<cleanupDaemonThreads>true</cleanupDaemonThreads>
<daemonThreadJoinTimeout>30000</daemonThreadJoinTimeout>
</configuration>
</plugin>
This plugin will run pl.avantis.iom.rest.DrupalQueriesImpl in phase prepare-package, this is a step just before package phase, so your Jar will contain the newest JSON file without downloading it manually .
Reference : [1] Maven Build Lifecycle [2] Codehaus - Exec Maven Plugin