I want to build two versions of an application, the only difference is I want to swap in a different version of one particular .java file. I already have a Maven build for building the source, plus an Ant build to then package up as a zip with an embedded JRE.
So I can modify my Ant build to create another zip file for this new build but what would be the best way to handle the rebuilding of the source with the single amended source file?
Updated With Progress
I have now subclassed the starting class with the main() method, so no longer have to swap source files around instead we simply need to pass a difference value for the mainClass in the manifest and we now only have one source tree to build.
So in my pom.xml I have :
org.apache.maven.plugins
maven-assembly-plugin
2.3
jar-with-dependencies
assembly.xml
com.companyname.StartClass
com.companyname
true
make-assembly
package
single
So can I have multiple of these assembly plugins so I can build two assemblies just differing in the manifest?
解决方案
Basically this is against a few of Maven's core concepts:
One project has one / that leads to one artifact.
An artifact with the same name ( derived from and by default) is supposed to have the same content.
There are a few solutions:
A property from a property file that's evaluated in an if to achieve different runtime behaviour. You don't prefer that.
A property defined via command line that's evaluated in an if.
A text from a resource file that's evaluated in an if. You don't prefer that.
A command line argument that's evaluated in an if.
A Java assertion, but cited from there: "Do not use assertions to do any work that your application requires for correct operation.".
One Maven way would be:
Create two additional projects (B, C) in addition to your current (A). A can be the parent of B and C to inherit common declarations.
B and C contain just the different source files.
Introduce two profiles in A's POM with and select one of the various activation methods:
B
...
com.example
B
...
AwithB
C
...
com.example
C
...
AwithC
Remember the second concept at the beginning: same name, same content (and behaviour). You can use the declaration in the profiles to adapt A's name accordingly.