Apache Maven, Software Development

Maven – Redirect console output to file

Sometimes we need to redirect Maven console output to a file. Your favorite IDEs may not display all the console output. It is normal as some IDEs have a default configuration to show only the last part of the overall output, which may still consist of a few hundred lines. The IDEs do not display all the lines if the console output is a lot.

Requirements For Maven

Maven requires Java, and we used Windows 10 for this post. Therefore, we need to install Java first before we run Maven. Next, we need to ensure we define an M2_HOME  environment variable. Then, we append the path to the Maven bin directory in the Path environment variable.

Maven Command-line Parameter To Redirect Console Output

In Apache Maven, we can write the console output to a file using a specific command-line parameter when running the application. To do just that, we use the --log-file parameter. For example,

Alternatively, you can configure your favorite IDEs to redirect Maven console output to a file.

Path To File Must Exist

We tested with Apache Maven 3.3.9. The path to the file must be an existing path. Otherwise, Maven writes out the output to the console. For more information, please visit https://maven.apache.org.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like