2

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?

twid
  • 6,368
  • 4
  • 32
  • 50

1 Answers1

1

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.

hgrey
  • 3,033
  • 17
  • 21
  • Problem with this is we need to get at library loading phase, So wont be able use `getClass()` and need at compile time... – twid Sep 21 '12 at 13:11
  • You don't need to add this information, cause this information is usually already added in the jar file. There exists a file META-INF/maven/${groupId}/${artifactId}/pom.properties. – khmarbaise Sep 21 '12 at 13:18
  • @khmarbaise: because we have many native libraries. and we need to load library with specific version... – twid Sep 21 '12 at 14:00