运行mvn clean package时禁用org.glassfish日志的问题求助
解决Maven打包时org.glassfish冗余日志问题
问题概述
执行mvn clean package时,终端输出大量来自org.glassfish依赖的冗余日志,包含org.glassfish.grizzly和org.glassfish.jersey相关内容。尝试以下方案未彻底解决:
- 通过
maven-surefire-plugin配置logging.properties文件,设置上述包的日志级别,无效果; - 使用
mvn clean package -q仅移除测试进度语句,冗余日志仍存在。
根因定位
经排查,问题源于pom.xml中系统属性配置方式的变更:
- 使用
<systemPropertyVariables>配置日志文件路径时,会触发冗余日志; - 改回原
<systemProperties>配置后,冗余日志消失,但导致一个单元测试失败。
可行解决方案尝试
1. 调整Surefire插件的日志配置优先级
确保logging.properties的配置能正确覆盖依赖的默认日志级别,可尝试在插件配置中明确指定日志配置文件的加载方式:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>你的插件版本</version> <configuration> <systemPropertyVariables> <java.util.logging.config.file>${project.basedir}/src/test/resources/logging.properties</java.util.logging.config.file> <!-- 强制指定日志管理器,避免依赖加载默认配置 --> <java.util.logging.manager>org.apache.juli.ClassLoaderLogManager</java.util.logging.manager> </systemPropertyVariables> </configuration> </plugin>
同时在logging.properties中确保配置生效:
org.glassfish.grizzly.level=SEVERE org.glassfish.jersey.level=SEVERE .handlers=java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.level=SEVERE
2. 修复<systemProperties>配置下的单元测试失败问题
如果切换回<systemProperties>后测试失败,需检查该测试是否依赖于<systemPropertyVariables>中的特定配置。可单独为失败的测试添加所需系统属性:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>你的插件版本</version> <configuration> <systemProperties> <property> <name>日志文件路径的key</name> <value>日志文件路径的value</value> </property> </systemProperties> <!-- 为失败的测试单独设置属性 --> <tests> <test> <includes> <include>**/失败的测试类名.java</include> </includes> <systemPropertyVariables> <需要的属性key>属性值</需要的属性key> </systemPropertyVariables> </test> </tests> </configuration> </plugin>
3. 排除不必要的GlassFish依赖
如果某些org.glassfish依赖并非项目必需,可在pom.xml中排除相关模块,减少日志来源:
<dependency> <groupId>你的依赖groupId</groupId> <artifactId>你的依赖artifactId</artifactId> <version>版本号</version> <exclusions> <exclusion> <groupId>org.glassfish</groupId> <artifactId>grizzly-http-server</artifactId> </exclusion> <exclusion> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-server</artifactId> </exclusion> </exclusions> </dependency>
内容的提问来源于stack exchange,提问作者commadelimited
相关产品推荐
相关产品推荐

