maven get properties at compile time

How can we get Maven properties in source file at compile time

pom.xml

<artifactId>myApp</artifactId>
<version>1.0.0</version>

Main.java

public class Main {
  private static final String artifactId = "project.artifactId";
  private static final String version = "project.version";
}

is it possible to hard cod in class?

Answers


You can use maven property to create java source file in generate-src directory and attach it via build helper maven plugin to the list of source folders.

You will control the contents of java file.

One way to create source java file is to use groovy maven plugin with inlining.


The question is not exactly a duplicate, but the answer I gave there explains how you can do that.

Generate a Version.java file in Maven


Need Your Help

a simple looping question

mysql loops

CREATE DEFINER = `dba`@`xx.xx.xx.3` PROCEDURE `oninjadb`.`TESTLOOPER`()

Paypal DPRA disable for this merchant message for recurring payment

php codeigniter paypal paypal-sandbox

I create test account on https://developer.paypal.com and in test account i set country as USA and account type is business. i have to configured recurring payment. but i still got this error

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.