me.at.coding
me.at.coding

Reputation: 17654

Override Java constant using Maven?

Using Maven, is it possible to override a Java constant?

Imagine I have

public static final String buildBy="Eclipse";

which when using Maven shall be changed to

public static final String buildBy="Maven";

Is that possible? Thanks :-)

Upvotes: 5

Views: 2858

Answers (3)

khmarbaise
khmarbaise

Reputation: 97407

The other possibility is to use the templating maven plugin which can be used to fulfill such purposes.

Upvotes: 2

MariuszS
MariuszS

Reputation: 31577

This is kind of Properties and should go to resource directory /src/main/resources where can be easily changed by maven (filtered).

Read also: Reading Properties file in Java

Upvotes: 0

Daniel Kaplan
Daniel Kaplan

Reputation: 67370

Yes this is possible with filters. But you'd have to put the file under your resource directory. You could put the java file under the resource directory, but a much better way would be to extract the value into a property file, put that file under resources and have maven filter the property file.

Upvotes: 4

Related Questions