Delete logger lines from final jar while performing maven build or package

Sunil Kumar Source

I know that it is possible to delete or skip files and folders while doing maven clean.

My problem is that I want to delete some specific lines ( lines) from final jar while doing mvn clean package.

My full codebase is filled with logger lines similar to the following codebase:

class MyClass {

  def main(args: Array[String]) {
    val log = Utils.getLogger"Application started")

    val url = """Trying to fetch content from url: $url")

    ..."Successfully fetched content. Doing something now.")

    val v1 = "variable1"
    val v2 = "variable2""Starting to do something with v1: $v1 and v2: $v2")

    try {

      ..."Successfully done something with variables")
    catch {
      case e: Exception =>
        log.severe(s"Failed to do something. Got exception with message: ${e.getMessage}")
    }"Continuing the work")

    ..."Finished everything")

  • These logger information helps me a lot in understanding the problem and where my codebase failed with reason. So I cannot remove them because I need them during development.
  • When I am building the Jar file for my clients (production artifact), I don't need any logging.
  • If required I can use a pattern to identify logger lines by searching as everywhere I am using the same variable name which is log.

My question is:

I don't know where and how to use this pattern to delete lines from final jar while doing mvn clean build package so that:

  1. there should be no logging.
  2. If I open up Jar file and convert .class to .java file then there should be no logging codebase.


  • My project is a mixture of Java & Scala codebase and I want to delete all lines where is found in any class be it Java or Scala in final jar.
  • I am using maven-assembly-plugin to create jar-with-dependencies as final product.
  • Any other solution is most welcomed.


comments powered by Disqus