Question: When running Maven in Eclipse, how do I send the console output to file?
I would like to achieve this using a pom setting or a maven plugin. I do not want to modify the run configurations or the maven system settings.
For reference, I am using Windows 7, Eclipse Luna, Java 6, Maven 3.
For this right-click the pom. xml file and select Run As Maven build. This opens a dialog which allows to define the parameters for the start. Enter clean verify in the Goals: field and press the Run button.
In order to enable detailed logs, use any of CLI Maven option, i.e. -X,--debug,-e,--errors. The result would be e.g.: [INFO] Surefire report directory: /path/to/project/target/surefire-reports. [INFO] Using configured provider org.
As per official command line options you could use -l,--log-file <arg>
which provide the:
Log file where all build output will go.
As such, running:
mvn clean install -l output.log
Would not print anything to the console and automatically redirect the whole build output to the output.log
file.
If you don't want to type it every time (or you actually don't want to use the command line) and you want it as default option (although rare case I would suppose), you could use new command line options behavior available since version 3.3.1 and have a .mvn
folder where the concerned pom.xml
file is located and a maven.config
file in it simply providing the following line:
-l output.log
That is, the .mvn/maven.config
file replaces MAVEN_OPTIONS
just for its project, locally where it has been created, with the options it provides, not impacting other builds as per Maven settings of MAVEN_OPTIONS
.
This is an IDE agnostic solution (it's a new built-in feature of Maven) and local to a project, but still not provided via simple POM editing, which cannot be achieved since the first phase of Maven default life cycle phases is validate
, which:
validate the project is correct and all necessary information is available
That is, during the build, hence when the build has already started (and generated output), it validates the pom.xml
file, hence too late to redirect build output at that stage based on some POM properties/plugin.
Go to run as and choose Run Configuration -> Commons -> Select a file
.
This should redirect your output to the file you specified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With