- "html": "\n<p><img src=\"https://img.shields.io/badge/build-passing-green.svg\"><img src=\"https://img.shields.io/badge/tests-passing-green.svg\"> <img src=\"https://img.shields.io/badge/license-Apache%202.0-blue.svg\"></p>\n<p><img src=\"https://raw.githubusercontent.com/cdimascio/java-dotenv/master/assets/java-dotenv.png\"> </p>\n<p>Dotenv is a zero-dependency module that loads environment variables from a <code>.env</code>. Storing configuration in the environment separate from code is based on The <a href=\"http://12factor.net/config\">The Twelve-Factor App</a> methodology.</p>\n<p><strong>Note:</strong> Java does not provide a way to set environment variables on a currently running process. Thus, once <code>java-dotenv</code> is configured, you can use the <code>dotenv.get("...")</code> API to get environment variables, instead of <code>System.getenv(...)</code>. <code>dotenv</code> should be used to retrieve all environment variables. Those listed in the host environment override those <code>.env</code>. </p>\n<h2>Install</h2>\n<h3>Maven</h3>\n<pre><span class=\"hljs-tag\"><<span class=\"hljs-name\">dependency</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">groupId</span>></span>io.github.cdimascio<span class=\"hljs-tag\"></<span class=\"hljs-name\">groupId</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">artifactId</span>></span>java-dotenv<span class=\"hljs-tag\"></<span class=\"hljs-name\">artifactId</span>></span>\n <span class=\"hljs-tag\"><<span class=\"hljs-name\">version</span>></span>1.1.0<span class=\"hljs-tag\"></<span class=\"hljs-name\">version</span>></span>\n<span class=\"hljs-tag\"></<span class=\"hljs-name\">dependency</span>></span></pre><h3>Gradle</h3>\n<pre>compile <span class=\"hljs-string\">'io.github.cdimascio:java-dotenv:1.1.0'</span></pre><h2>Usage</h2>\n<h3>Create a <code>.env</code> file</h3>\n<pre># formatted as key=value\nMY_ENV_VAR1=My first env var configure dotenv\nMY_EVV_VAR2=My second env var</pre><h3>Configure</h3>\n<p>Configure <code>java-dotenv</code> once in your application. \nSee below for <a href=\"#kotlin-usage\">Kotlin usage</a></p>\n<pre>Dotenv dotenv = Dotenv.Instance\n .configure()\n .build();</pre><p>see <a href=\"#configuration-options\">configuration options</a></p>\n<h3>Get environment variables</h3>\n<p>Note, environment variables specified in <code>.env</code> take precedence over those configured in the actual environment.</p>\n<pre>dotenv.get(<span class=\"hljs-string\">"MY_ENV_VAR1"</span>);</pre><h2>Configuration options</h2>\n<h3><em>optional</em> <code>directory(path: String)</code></h3>\n<p><code>path</code> specifies the directory containing <code>.env</code>. Dotenv first searches for <code>.env</code> using the given path on the filesystem. If not found, it searches the given path on the classpath. If <code>directory</code> is not specified it defaults to searching the current working directory on the filesystem. If not found, it searches the current directory on the classpath.</p>\n<h3><em>optional</em> <code>ignoreIfMalformed()</code></h3>\n<p>Do not throw when <code>.env</code> entries are malformed. Malformed entries are skipped.</p>\n<h3><em>optional</em> <code>ignoreIfMissing()</code></h3>\n<p>Do not throw when <code>.env</code> does not exist. Dotenv will continue to retrieve environment variables that are set in the environment e.g. <code>dotenv["HOME"]</code></p>\n<h2>Configuration examples</h2>\n<pre>Dotenv dotenv = Dotenv.Instance\n .configure()\n .directory(<span class=\"hljs-string\">"./some/path"</span>)\n .ignoreIfMalformed()\n .ignoreIfMissing()\n .build();</pre><h2>Kotlin usage</h2>\n<h3>Configure</h3>\n<p>Configure <code>java-dotenv</code> once in your application. (see below for <a href=\"#configure-(using-java-8\">Java</a>) usage)</p>\n<pre><span class=\"hljs-keyword\">val</span> dotenv = Dotenv.configure().build()</pre><p>see <a href=\"#configuration-options\">configuration options</a></p>\n<h3>Get environment variable</h3>\n<p>Note, environment variables specified in <code>.env</code> take precedence over those configured in the actual environment.</p>\n<pre>dotenv[<span class=\"hljs-string\">"MY_ENV_VAR1"</span>]</pre><p>with configuration options</p>\n<pre><span class=\"hljs-keyword\">val</span> dotenv = Dotenv\n .configure()\n .directory(<span class=\"hljs-string\">"./some/path"</span>) <span class=\"hljs-comment\">// set the directory containing .env</span>\n .ignoreIfMalformed() <span class=\"hljs-comment\">// do not throw an error if .env is malformed</span>\n .ignoreIfMissing() <span class=\"hljs-comment\">// do not throw an error if .env is missing</span>\n .build()</pre><h2>Examples</h2>\n<ul>\n<li>with <a href=\"https://github.com/cdimascio/kotlin-swagger-spring-functional-template\">Spring Framework</a> </li>\n</ul>\n<h2>License</h2>\n<p><a href=\"https://www.apache.org/licenses/LICENSE-2.0\">Apache 2.0</a></p>\n"
0 commit comments