How to change the default output from a Maven 2 / Cobertura instrument goal?

when i instrument my classes using Maven 2 using the command

mvn cobertura:instrument

The output (the instrumented classes) are put in \target\generated-classes. Is there a way to change the output location to \target\classes?

I checked the instrumentation tasks of the cobertura-maven plugin but this does not give me a solution sofar.


As far as I understand, the instrumented classes are only needed by cobertura for report generation. If you create them in target/classes, they will overwrite the original class files.

If you need the instrumented files in a jar as a result, you can configure the maven-jar-plugin to pick up the files from the target/generated-classes directory instead of or in addition to the files from the standard ${build.project.outputDirectory}.


Have a look at the maven-jar-plugin description. To only use target/generated-classes, the following addition to your POM should work - try it and modify it to your needs:

        <version>2.3</version> <!-- replace with correct version nbr! -->


${} points to your target folder, ${} to target/classes. I do not know if you can simply set ${} to a new value - have a look at the this chapter of the maven book, maybe you find some hints

Edit 2

Alternativly or additionally you can use maven to copy the files from target/generated-classes to target/classes after coberture:instrument has finished. This question has one answer with an example POM (fragment), you just have to identify the correct phase (process-resources is definitely too early for your case)

You have not said why you want to overwrite the default location, but I assume it is so that you can use the instrumented classes from another project, or perhaps include them in a web archive or something similar.

I added the following to my pom.xml


This makes maven generate an additional jar file called projectname-instrumented.jar

It is then possible to depend on this jar file from any other pom (including for example a web module) using


I did not test this 100% but have used similar mechanisms in the past

Did you try "mvn cobertura:instrument install"? It will generate a jar file including all the cobertura version classes. If you want to change back original version, just run the command without "cobertura:instrument".

I just implemented the solution proposed by Andreas_D, modified my pom and uses the maven-resources-plugin. So on some stage of my build the Cobertura generated files are copied to the /target/classes directory.

You can configure it using <classesDirectory>[Your DIR]</classesDirectory>

In cobertura-maven-plugin version 2.4 this is still not supported. I've just created an improvement ticket, patch is attached to the ticket.

Need Your Help

Powerpoint upload stops at ~9MB with cURL -F

curl convertapi

I have a problem using PowerPoint2Pdf conversion, when uploading files that are larger than 9MB. I can upload at least 43MB PowerPoint files through the browser form without problems...

Is there a way to set custom color for status bar text and background?

ios storyboard

I know how to change text color to black or white, but is there some way to change text to green and BG to red for example?