2017-08-17 3 views

答えて

0

のMavenのpom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>wendelsilverio</groupId> 
    <artifactId>hello-maven</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>Hello</name> 
</project> 

あなたは作成にプログラム的に内部に行うことができますjar:

public String getVersion() { 
    String version = null; 

    // try to load from maven properties first 
    try { 
     Properties p = new Properties(); 
     InputStream is = PomVersionMain.class 
       .getResourceAsStream("/META-INF/maven/wendelsilverio/hello-maven/pom.properties"); 
     if (is != null) { 
      p.load(is); 
      version = p.getProperty("version", ""); 
     } 
    } catch (Exception e) { 
     // ignore 
    } 

    // fallback to using Java API 
    if (version == null) { 
     Package aPackage = PomVersionMain.class.getPackage(); 
     if (aPackage != null) { 
      version = aPackage.getImplementationVersion(); 
      if (version == null) { 
       version = aPackage.getSpecificationVersion(); 
      } 
     } 
    } 

    if (version == null) { 
     // we could not compute the version so use a blank 
     version = "Version could not compute"; 
    } 

    return version; 
} 
関連する問題