From what I am seeing, your setup is just right. Having the maven resource folder and the java folder both under "main" is totally fine.
I had a problem with the filename of the properties file. I still do not understand why, but as soon I changed the name from application.properties
to whateverYouWant.properties
it suddenly works.
And have you enabled filtering for maven resources in the pom.xml?
<build>
<!--Allows access to maven resources-->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
Here is a guide from Alex Miller Retrieve version from maven pom.xml in code
And here is the full code example for accessing the properties in java code (I know you posted already nearly all of it, but just in case if somebody stumbles upon this post)
public String getVersionNumber() {
String version = "";
ClassLoader classLoader = getClass().getClassLoader();
final Properties properties = new Properties();
try {
properties.load(classLoader.getResourceAsStream("main.properties"));
version = properties.getProperty("application.version");
} catch (IOException ioException) {
log.log(Level.WARNING, "Version number could not be retrieved from maven resources.");
} catch (NullPointerException nullPointerException) {
log.log(Level.WARNING, "Cannot find .properties file to read version number");
}
return version;
}