
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
com.github.sitture:env-config
Advanced tools
A simple utility to manage environment configs in Java-based projects by merging *.properties files with environment variables overrides.
A simple utility to manage environment configs in Java-based projects by merging *.properties
files with environment variables overrides.
All notable changes to this project are documented in CHANGELOG.md. The format is based on Keep a Changelog and adheres to Semantic Versioning.
Add the following dependency to use this EnvConfig:
<dependency>
<groupId>com.github.sitture</groupId>
<artifactId>env-config</artifactId>
<version>${version}</version>
</dependency>
If you would like to use github package instead of maven central, add the following repository to pom.xml.
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/sitture/env-config</url>
</repository>
</repositories>
compile 'com.github.sitture:env-config:${version}'
system property | environment variable | description |
---|---|---|
env.config.path | ENV_CONFIG_PATH | The base directory where the configuration files are lived. default: config directory under the project. |
env.config.environment | ENV_CONFIG_ENVIRONMENT | The environment to activate. default: default directory under the base configuration directory. |
env.config.profiles.path | ENV_CONFIG_PROFILES_PATH | The base directory where the profile based configuration files are lived. default: ${env.config.path}/${env.config.environment}/ |
env.config.profile | ENV_CONFIG_PROFILE | The profile to activate from the active environment directory. |
env.config.keepass.enabled | ENV_CONFIG_KEEPASS_ENABLED | Whether to load properties from a keepass file. default: false |
env.config.keepass.filename | ENV_CONFIG_KEEPASS_FILENAME | The keepass filename to load from the resources folder (src/main/resources). default: the root project directory name. i.e. project.build.directory |
env.config.keepass.masterkey | ENV_CONFIG_KEEPASS_MASTERKEY | The password to open the keepass file. This is required if env.config.keepass.enabled=true . |
env.config.vault.enabled | ENV_CONFIG_VAULT_ENABLED | Whether to load properties from a vault secret. default: false |
env.config.vault.address | ENV_CONFIG_VAULT_ADDRESS | The host address of the vault instance. This is required if env.config.vault.enabled=true . |
env.config.vault.namespace | ENV_CONFIG_VAULT_NAMESPACE | The vault namespace to look for secrets. This is required if env.config.vault.enabled=true . |
env.config.vault.default.secret.path | ENV_CONFIG_VAULT_DEFAULT_SECRET_PATH | The base secret path for the project. This is optional when there's a shared secret across multiple projects. |
env.config.vault.secret.path | ENV_CONFIG_VAULT_SECRET_PATH | The base secret path for the project. This is required if env.config.vault.enabled=true . |
env.config.vault.token | ENV_CONFIG_VAULT_TOKEN | The vault token used for authentication. This is required if env.config.vault.enabled=true . |
System.getProperties()
System.getenv()
config/${env.config.environment}/${env.config.profile}/*.properties
config/default/${env.config.profile}/*.properties
config/${env.config.environment}/*.properties
config/default/*.properties
To start using this:
config
directoryThe default required directory for configuration files in config
under project root. This can be overridden by ENV_CONFIG_PATH
environment variable.
config
in project root.config
environmentsThe default environment is set to default
and can be overridden by ENV_CONFIG_ENVIRONMENT
environment variable.
default
environment subdirectory under config
directory.default.properties
file in the default
directory. E.g. config/default/default.properties
# formatted as key=value
my.first.property=my_first_value
my.second.property=my_second_value
You can add multiple .properties
files under environment directory. E.g. You may want to split the properties into:
.
├── config
│ └── default
│ ├── default.properties
│ └── db.properties
You can create as many environments as needed.
.
├── config
│ └── default
│ ├── default.properties
│ └── db.properties
│ └── integration
│ └── integration.properties
config
profilesYou can also have config profiles within an environment directory by specifying the ENV_CONFIG_PROFILE=profile1
variable E.g.
.
├── config
│ └── default
│ └── profile1
│ └── profile1.properties
│ └── profile2
│ └── profile2.properties
│ └── default.properties
│ └── integration
│ └── profile1
│ └── profile1.properties
│ └── integration.properties
If ENV_CONFIG_ENVIRONMENT=integration
and ENV_CONFIG_PROFILE=profile1
suggests to load properties in the following order:
integration/profile1/profile1.properties
default/profile1/profile1.properties
integration/integration.properties
default/default.properties
You can base an environment based on another by specifying multiple environment in ENV_CONFIG_ENVIRONMENT
environment variable.
E.g. if you would like env2
environment to inherit properties from env2
environment:
ENV_CONFIG_ENVIRONMENT=env1,env2
The above will load environment properties from env2 on top of env1 and finally the default properties from default environment.
KeePass
Database EntriesIf you have secret passwords which cannot be stored as plain text within project repository, you can store them into a password-protected KeePass database file.
src/main/resources
or src/test/resources
.ENV_CONFIG_KEEPASS_ENABLED
- A flag to enable reading of the keePass file. Default is set to false
.ENV_CONFIG_KEEPASS_FILENAME
- This is the name of the DB file. Default is the name of project directory.ENV_CONFIG_KEEPASS_MASTERKEY
- The key to access the DB file.keepass.kdbx
then top level group should be keepass
.default
group for the default environment.default
group will be shared across all environments similar to the environment directories behaviour.The EnvConfig
will go through properties set under your environment and then load properties from default environment ignoring the ones already set. You can keep the shared properties under your default
environment without having to repeat them in every other environment.
You can get the current environment by:
EnvConfig.getEnvironment();
EnvConfig.get("...")
To get a property set either in the properties file, system property or environment variable:
EnvConfig.get("my.property");
EnvConfig.getInt("my.property");
EnvConfig.getBool("my.property");
EnvConfig.getList("my.property"); // will return a List<String> from a comma separated String.
required
property// when a property is required to continue
EnvConfig.getOrThrow("my.property");
If the property isn't set then a EnvConfigException
is thrown.
defaultValue
// return a default value when a property isn't found
EnvConfig.get("my.property", "defaultValue");
Note: All the environment variable names are set to properties naming convention.
E.g. MY_ENV_VAR
can either be accessed by EnvConfig.get("my.env.var");
or EnvConfig.get("MY_ENV_VAR");
You can override any property set in the environment properties file by setting an system environment variable.
E.g. my.env.property
can be overridden by MY_ENV_PROPERTY
environment variable.
EnvConfig.add("...")
You can add key/value pairs to the EnvConfig to be accessed somewhere else in the project.
EnvConfig.add("my.property", "my_value");
EnvConfig.set("...")
You can set/update an existing property in EnvConfig:
EnvConfig.set("my.property", "my_value");
The .set(...)
can be used for both existing and non-existing properties.
EnvConfig.clear("...")
You can clear an existing property in EnvConfig:
EnvConfig.clear("my.property")
EnvConfig.asMap()
You can get a full list of available properties with EnvConfig.asMap()
which is a combination of properties from config
directory, system properties and all environment variables.
Please open an issue here on GitHub if you have a problem, suggestion, or other comment.
Pull requests are welcome and encouraged! Any contributions should include new or updated unit tests as necessary to maintain thorough test coverage.
Read CONTRIBUTING.md for guidelines.
FAQs
A simple utility to manage environment configs in Java-based projects by merging *.properties files with environment variables overrides.
We found that com.github.sitture:env-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.