BAEL-6773: Get the OS Username in Java (#14848)

* BAEL-6773: Removed Ignored Tests

* BAEL-6773: Initializing a New Module

* BAEL-6773: user.name Property Example

* BAEL-6773: Removed Unused Dependencies
This commit is contained in:
Eugene Kovko
2023-09-28 18:04:54 +02:00
committed by GitHub
parent 2dc953dcad
commit eabaf2764d
7 changed files with 103 additions and 89 deletions
@@ -0,0 +1,26 @@
*.class
0.*
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
.resourceCache
# Packaged files #
*.jar
*.war
*.ear
# Files generated by integration tests
*.txt
backup-pom.xml
/bin/
/temp
#IntelliJ specific
.idea/
*.iml
@@ -0,0 +1,7 @@
## Core Java OS
This module contains articles about working with the operating system (OS) in Java
### Relevant Articles:
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>core-java-os</artifactId>
<name>core-java-os</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<finalName>core-java-os</finalName>
<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>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
</project>
@@ -0,0 +1,9 @@
package com.baeldung.system;
public class EnvironmentExample {
public void getUserName() {
String username = System.getenv("USERNAME");
System.out.println("User: " + username);
}
}
@@ -0,0 +1,19 @@
package com.baeldung.system;
public class PropertiesExample {
public void getUserName() {
String username = System.getProperty("user.name");
System.out.println("User: " + username);
}
public void getCustomProp() {
String customProperty = System.getProperty("custom.prop");
System.out.println("Custom property: " + customProperty);
}
public void getCustomPropWithFallback() {
String customProperty = System.getProperty("non-existent-property", "default value");
System.out.println("Custom property: " + customProperty);
}
}