public static String getPomVersion ( ) { String cmd = "mvn help:evaluate -Dexpression=project.version " + "-q -DforceStdout" ; Process process = null ; InputStreamReader isr = null ; try { process = Runtime . getRuntime ( ) . exec ( cmd ) ; process . waitFor ( ) ; isr = new InputStreamReader ( process . getInputStream ( ) ) ; BufferedReader br = new BufferedReader ( isr ) ; return br . readLine ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } finally { if ( isr != null ) { try { isr . close ( ) ; } catch ( Exception ignored ) { } } // Destroy child process if ( process != null ) { process . destroy ( ) ; } } }
Get version from pom . xml