feat(ext_prop): initial commit

This commit is contained in:
dancingCycle 2022-04-20 08:59:50 +02:00
parent 05d35609fd
commit ee3b8c046e
4 changed files with 148 additions and 0 deletions

5
ext-properties/README.md Normal file
View File

@ -0,0 +1,5 @@
# Overview
This project can serve as starting point for Maven and Java based projects using externl properties.
# Links

113
ext-properties/pom.xml Normal file
View File

@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>ext_prop</name>
<description>description</description>
<url>https://swingbe.de</url>
<groupId>de.swingbe</groupId>
<artifactId>ext_prop</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<licenses>
<license>
<name>GNU General Public License</name>
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url>
</license>
</licenses>
<scm>
<url>https://github.com/Software-Ingenieur-Begerad/sandbox-java</url>
</scm>
<properties>
<!-- Other properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.properties>src/main/resources/version.properties</version.properties>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<!-- Target Java versions -->
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<!-- exclude signatures from merged JAR to avoid invalid signature messages -->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!-- The shaded JAR will not be the main artifact for the project, it will be attached
for deployment in the way source and docs are. -->
<shadedArtifactAttached>true
</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>de.swingbe.ext_prop.Main
</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<files>
<file>src/main/resources/version.properties</file>
</files>
<outputFile/>
<properties/>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,29 @@
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));
}
}
}

View File

@ -0,0 +1 @@
version = ${project.version}