In Maven, how output the classpath being used?

后端 未结 7 1308
庸人自扰
庸人自扰 2020-12-12 23:31

For my current purposes I have a Maven project which creates a war file, and I want to see what actual classpath it is using when creating the war.

7条回答
  •  温柔的废话
    2020-12-13 00:31

    This is a single command solution but does compile the code.

    mvn -e -X -Dmaven.test.skip=true clean compile | grep -o -P '\-classpath .*? ' | awk '{print $2}'
    
    • It's based in Philip Helger's previous answer (Thanks by the way)

    Shell script example usage

    MAVEN_CLASSPATH=$(mvn -e -X -Dmaven.test.skip=true clean compile | grep -o -P '\-classpath .*? ' | awk '{print $2}')
    

    I used a variation of it in a shell script to run a standalone main() (for Hibernate schema generation) this way

    #/bin/bash
    
    MAVEN_TEST_CLASSPATH=$(mvn -e -X clean package | grep -o -P '\-classpath .*?test.*? ')
    
    java $MAVEN_TEST_CLASSPATH foo.bar.DBSchemaCreate
    

    File output example

    mvn -e -X -Dmaven.test.skip=true clean compile | grep -o -P '\-classpath .*? ' | awk '{print $2}' > maven.classpath
    

提交回复
热议问题