maven 只用于java吗,使用Maven,如何仅使用一个不同的.java文件构建Java项目的两个版本?...

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值