feat(ext_prop): add build properties
This commit is contained in:
parent
ee3b8c046e
commit
5e0136eb22
|
@ -9,7 +9,7 @@
|
|||
<url>https://swingbe.de</url>
|
||||
<groupId>de.swingbe</groupId>
|
||||
<artifactId>ext_prop</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<licenses>
|
||||
|
@ -26,7 +26,9 @@
|
|||
<properties>
|
||||
<!-- Other properties -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<version.properties>src/main/resources/version.properties</version.properties>
|
||||
<app.date>${maven.build.timestamp}</app.date>
|
||||
<maven.build.timestamp.format>yyyy-MM-dd:HH:mm:ss</maven.build.timestamp.format>
|
||||
<app.version>${pom.version}</app.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
@ -103,6 +105,7 @@
|
|||
<configuration>
|
||||
<files>
|
||||
<file>src/main/resources/version.properties</file>
|
||||
<file>src/main/resources/build.properties</file>
|
||||
</files>
|
||||
<outputFile/>
|
||||
<properties/>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package de.swingbe.ext_prop;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class BuildProperties {
|
||||
private final Properties properties;
|
||||
|
||||
private final java.net.URL url;
|
||||
|
||||
public BuildProperties() {
|
||||
url = ClassLoader.getSystemResource("build.properties");
|
||||
properties = new Properties();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
try {
|
||||
properties.load(url.openStream());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return properties.getProperty("build.version");
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
|
||||
try {
|
||||
properties.load(url.openStream());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return properties.getProperty("build.date");
|
||||
}
|
||||
}
|
|
@ -1,28 +1,14 @@
|
|||
package de.swingbe.ext_prop;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello world!");
|
||||
Properties properties = new Properties();
|
||||
java.net.URL url = ClassLoader.getSystemResource("version.properties");
|
||||
|
||||
try {
|
||||
properties.load(url.openStream());
|
||||
} catch (FileNotFoundException fie) {
|
||||
fie.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("version: " + properties.getProperty("version"));
|
||||
Set<String> keys = properties.stringPropertyNames();
|
||||
for (String key : keys) {
|
||||
System.out.println(key + " - " + properties.getProperty(key));
|
||||
}
|
||||
VersionProperties versionProperties = new VersionProperties();
|
||||
System.out.println("version: " + versionProperties.getVersion());
|
||||
BuildProperties buildProperties = new BuildProperties();
|
||||
System.out.println("build.version: " + buildProperties.getVersion());
|
||||
System.out.println("build.date: " + buildProperties.getDate());
|
||||
System.out.println("Done!");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package de.swingbe.ext_prop;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class VersionProperties {
|
||||
private final Properties properties;
|
||||
|
||||
private final java.net.URL url;
|
||||
|
||||
public VersionProperties() {
|
||||
url = ClassLoader.getSystemResource("version.properties");
|
||||
properties = new Properties();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
|
||||
try {
|
||||
properties.load(url.openStream());
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return properties.getProperty("version");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
build.version=${app.version}
|
||||
build.date=${app.date}
|
Loading…
Reference in New Issue