Running JUnit tests in IDEA does not respect/consume pom.xml configuration of maven-surefire-plugin

已回答

In pom.xml I have:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemProperties>
<property>
<name>catalina.home</name>
<value>${project.build.directory}</value>
</property>
</systemProperties>
</configuration>
</plugin>

and in log4j.xml I have:

 <appender name="file" class="org.apache.log4j.RollingFileAppender">
...
  <param name="file" value="${catalina.home}/logs/mdht-restlet.log" />
...
</appender>

However, despite having logs/mdht-restlet.log off the root of my project, log4j informs me that

log4j:ERROR setFile(null,false) call failed.
java.io.FileNotFoundException: /logs/mdht-restlet.log (No such file or directory)

Is this just not supposed to work? Is there some other way to trick IntelliJ into making this work?

Thanks!

0

It now works, though the log file isn't where I wanted it to be, but this is my fault by choosing the wrong Maven/system property. After changing the maven-surefire-plugin configuration in pom.xml to this:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<catalina.home>${project.build.directory}</catalina.home>
</systemPropertyVariables>
</configuration>
</plugin>

I'm now getting:

log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Level value for root is [TRACE].
log4j: root level set to TRACE
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.EnhancedPatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1.} - %m%n].
log4j: Adding appender named [console] to category [root].
log4j: Class name: [org.apache.log4j.RollingFileAppender]
log4j: Setting property [append] to [false].
log4j: Setting property [maxFileSize] to [10MB].
log4j: Setting property [maxBackupIndex] to [10].
log4j: Setting property [file] to [/home/russ/sandboxes/mdht-restlet.next_release.dev/code/mdht-restlet/target/logs/mdht-restlet.log].
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1.}:%L - %m%n].
log4j: setFile called: /home/russ/sandboxes/mdht-restlet.next_release.dev/code/mdht-restlet/target/logs/mdht-restlet.log, false
log4j: setFile ended
log4j: Adding appender named [file] to category [root].
2018-06-26 08:52:01 ERROR c.i.p.Header - There is no patient defined

And the last line above, which goes to the console, also goes to file mdht-restlet/target/logs/mdht-restlet.log. I see this as success, though I have something to fix on my part.

Thank you very much, Yaroslav!

0

请先登录再写评论。