Include the POM version in Doxygen? - maven

I use Doxygen to document my project. My project uses Maven and thus contains a POM file with a version.
Is it possible to reuse this version number as PROJECT_NUMBER in Doxygen?

Maven has the ability to filter files and replace Maven properties with actual values. If your doxygen configuration file is in your src/main/resources/... path, you can simply add:
<project>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Then you can reference ${project.version} in your doxygen file and it will be replaced with the version number.

Related

Why spring only picks from src/main/resources folder to add to classpath?

Why spring only picks from src/main/resources folder to add to classpath ?
That is the default folder for spring spring maven project config.
If you want to change it you can see the example here:
http://www.mkyong.com/maven/how-to-change-maven-resources-folder-location/
Otherwise for Annotated version you can view the Web Tutorial on the Spring.IO website:
http://spring.io/guides/tutorials/web/
Maven uses default classpath for the resource folder which is "src/main/resources"
if you want to include your own custom folder to class path, you have to update pom.xml file to indicate maven to include your new folder into classpath. use following code template to update pom.xml
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
.....
<resource>
<directory>path to your folder to put in classpath</directory>
</resource>
</resources>
</build>
if your pom.xml file doesn't have build or resource tag already then just add only add following piece of code to pom.xml
<build>
</resources>
<resource>
<directory>path to your folder to put in classpath</directory>
</resource>
</resources>
</build>
and check your Effective POM to verify that your custom folder and resource folder both are present there or not.

maven clean install lost resource folder

I was trying to use maven to build my project
when I create a source folder src/main/resource and put a file into that folder.
But when I do "mvn clean install eclipse:clean eclipse:eclipse", src/main/resource folder gone, it appears to the src folder instead
The problem of this new structure for me is that I have to manually create a src/main/resource folder again to make sure that those files in the resource folder could be deployed into classpath when I run it. I wonder if there is a way to let maven do it automatically for me? Thanks
You can specify the resources directory in pom.xml. Following is the example:
<build>
<directory>target</directory>
<outputDirectory>target/classes</outputDirectory>
<finalName>${artifactId}-${version}</finalName>
<testOutputDirectory>target/test-classes</testOutputDirectory>
<sourceDirectory>src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
reference: http://maven.apache.org/guides/introduction/introduction-to-the-pom.html

maven pom's resource element

i am new to maven and came across the resources section. The reference for the maven project descriptor (version 4.0) states that "this element describes all of the classpath resources associated with a project or unit tests" (link). However this description i do not understand/seems to abstract for me. Why would i want to describe classpath resources? How does it affect the projects lifecycle?
matthias
usually you have the src/main/resources folder which contains resources which will be packaged into a jar. This everything which is in the above folder will automatically be packaged into a jar and is accessible via getResource... Via the resources area in the pom you can filter files from their way src/main/resources to the target/classes folder.
<project>
...
<name>My Resources Plugin Practice Project</name>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
...
</resources>
...
</build>
...
</project>
The lifecycle of Maven is not influenced by this.
This feature allows you, for example, to use Maven variables inside your .properties files. Just declare the directory, where your .properties are, in <resources> section, and you'll be able to use ${project.name} or whatever.
pom.xml:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
version.properties:
version=${pom.version}
timestamp=${timestamp}
(${timestamp} is created with Maven Build Number plugin).

Maven Properties not referenced in properties file

I have some properties in my maven pom.xml.
<properties>
<number>3</number>
<age>38</age>
</properties>
(They are random properties)
In a properties file, lets call it resource.properties, I have the following:
value1 = ${number}
value2 = ${age}
When spring tries to read properties from this file, it cannot get the reference from ${number} saying that it cannot be found.
Why is this and how can I make it work? Or is doing this not possible at all.
EDIT: I have enabled filtering but still does not work. My resource is in the src/test/resources directory.
Here is the part of the pom where I enable filtering.
<build>
...
<resources>
<resource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
you need to tell maven which files it uses to replace placeholders e.g
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
see maven filter
You should enable resource filtering for the maven resources plugin as shown below:
...
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
See the Maven Resources Plugin section about filtering for details.

Maven: how to place resource file together with jar?

I have \src\main\resources\logback.xml file. When I run mvn package it is placed into the jar by default. How do I make Maven place it next to jar, not inside?
So, well, I just want Maven to copy the resource to the same folder where jar will be.
No plugin definitions needed, just edit the build resources:
<build>
<resources>
<!-- regular resource processsing for everything except logback.xml -->
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>logback.xml</exclude>
</excludes>
</resource>
<!-- resource processsing with a different output directory
for logback.xml -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>logback.xml</include>
</includes>
<!-- relative to target/classes
i.e. ${project.build.outputDirectory} -->
<targetPath>..</targetPath>
</resource>
</resources>
</build>
Reference:
process-resources
(Maven Book)
<build><resources> (POM
Reference)
You can build a ZIP file containing both using the Maven Assembly plugin.
You can also use Maven Antrun plugin or similar to put whatever file you want but the idea of single artifact per project is built deep into Maven internals so there is a chance it will hunt you down elsewhere.
Exclude that file:
http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
And then use the Maven Antrun plugin to copy the file.
However, the latter part does not make much sense. If it is a configuration file to put in a server, simply manually copy it.

Resources