Generate an xml file with all dependencies with maven

前端 未结 4 1228
温柔的废话
温柔的废话 2020-12-28 21:47

I need to generate module.xml file for JBoss7 for a maven project which has a lot of jar-dependencies. What is the easiest way to do it? The file looks like:

4条回答
  •  一个人的身影
    2020-12-28 21:55

    This can be easily solved in a few steps.

    1. run mvn dependency:list -DoutputFile=dep.list -DoutputAbsoluteArtifactFilename=true in your shell

      you will receive a file like this:

      The following files have been resolved:
          ch.qos.logback:logback-classic:jar:0.9.30:test:C:\Dokumente und Einstellungen\michael-o.m2\repository\ch\qos\logback\logback-classic\0.9.30\logback-classic-0.9.30.jar
          ch.qos.logback:logback-core:jar:0.9.30:test:C:\Dokumente und Einstellungen\michael-o.m2\repository\ch\qos\logback\logback-core\0.9.30\logback-core-0.9.30.jar
          classworlds:classworlds:jar:1.1-alpha-2:compile:C:\Dokumente und Einstellungen\michael-o.m2\repository\classworlds\classworlds\1.1-alpha-2\classworlds-1.1-alpha-2.jar
      

      The important information is indented by 4 spaces in the file.

    2. Now grep out the important information and do not forget to limit to compile and runtime scope.

    3. split columns with cut -d ':' -f and get the last column.
    4. Get the filename after the last (back)slash.
    5. Now build an XML file with the information.

    Every can be packed in a nice shell script.

    See the maven-dependency-plugin for reference.

    A quick command looks like this: cat dep.list | grep -E ':(compile|runtime):' | cut -d ':' -f 7 | sed -e 's/\///g' | xargs -I {} basename '{}' | xargs -I {} echo ""

    The output contains the jar files names:

    
    
    
    
    
    
    
    

    Now wrap with XML header and footer, and you are done!

提交回复
热议问题