I want to save maven output to a file, but without loosing the output to console. Usage of tee
is not an option because I run under Windows and also I do not want to add a binary tee.exe to the source tree.
Asked
Active
Viewed 5.6k times
19

sorin
- 161,544
- 178
- 535
- 806
-
3There is really nothing maven-specific about this. I'd suggest asking on SuperUser.com if there is a way to redirect cmd output to both a file and the console. – Sean Patrick Floyd Jan 20 '11 at 11:39
-
2This is *specific* to maven and it looks that maven does not support this yet, this being really ugly for a build system. – sorin Jan 24 '11 at 12:01
-
According to @Sean comment, here are possible workarounds [How to redirect output to a text file and the console (cmd) window at the same time?](http://superuser.com/a/111854/24948) or [Displaying Windows command prompt output and redirecting it to a file](http://stackoverflow.com/a/796492/251745) – chepseskaf Jul 24 '12 at 11:42
7 Answers
10
If you are using linux. you can use the bellow command.
mvn install -X | tee log.txt

Varun
- 4,342
- 19
- 84
- 119
-
1
-
2@Sridhar-Sarnobat I would expect by passing the command you've told maven (mvn) to save the logs to the file versus the default location (which on my system is 'System.out'). This is why you don't get the console output. Just look at the log files when saving to file. Side note - default logging location can be changed if needed via the ${MAVEN_HOME}/conf/logging/simplelogger.properties file. Here is a link if you need it: https://maven.apache.org/maven-logging.html – Zack Jannsen Mar 02 '16 at 11:40
-
1@ZackJannsen not true. Other commands work fine. But thanks for the reply – Sridhar Sarnobat Mar 23 '16 at 06:23
-
-
-
tee command is available for Windows too. It is inside Cygwin package. Maybe manual selection of tee is needed. – JRr Jan 21 '22 at 16:02
8
Maven 3 command output can be redirected now. See the below command on windows:
mvn -X install > test.log
This will redirect the command output to test.log file ,located in the current directory.

Manmohan_singh
- 1,776
- 3
- 20
- 29

Vishnu
- 1,011
- 14
- 31
-
3I don't think this solves the problem of dumping it to the console simultaneous which is why he wants to use tee. – Sridhar Sarnobat Mar 23 '16 at 06:25
2
Use Powercmd. It works as like normal command prompt plus some additional features like automatically log everything on screen, multiple windows, shortcuts.

Shailesh Pratapwar
- 4,054
- 3
- 35
- 46
2
Since you said you're on windows. In powershell there is the Tee-Object
. I run maven as such: (note that in powershell you'll need to enclose the whole -Dexec.args
in quotes).
mvn exec:java "-Dexec.mainClass=com.proj.main" "-Dexec.args=arg0 arg1" | Tee-Object -FilePath output.log

Dave Baghdanov
- 2,288
- 5
- 24
- 35
2
Use :
> file-name
at the end of your mvn command to send output to a file then use something like wintail to tail the file.

wr1472
- 21
- 1
- 5