{"id":13485611,"url":"https://github.com/shyiko/dotenv","last_synced_at":"2025-08-19T10:18:10.519Z","repository":{"id":57722790,"uuid":"97261581","full_name":"shyiko/dotenv","owner":"shyiko","description":"A twelve-factor configuration (12factor.net/config) library for Java 8+","archived":false,"fork":false,"pushed_at":"2018-02-07T21:02:54.000Z","size":61,"stargazers_count":47,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-11T22:26:06.901Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shyiko.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-14T18:20:08.000Z","updated_at":"2025-03-22T06:05:24.000Z","dependencies_parsed_at":"2022-08-28T08:40:45.710Z","dependency_job_id":null,"html_url":"https://github.com/shyiko/dotenv","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shyiko/dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyiko%2Fdotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyiko%2Fdotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyiko%2Fdotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyiko%2Fdotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shyiko","download_url":"https://codeload.github.com/shyiko/dotenv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shyiko%2Fdotenv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271135539,"owners_count":24705102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T18:00:27.915Z","updated_at":"2025-08-19T10:18:10.492Z","avatar_url":"https://github.com/shyiko.png","language":"Java","readme":"# dotenv [![Build Status](https://travis-ci.org/shyiko/dotenv.svg?branch=master)](https://travis-ci.org/shyiko/dotenv) [![Maven Central](https://img.shields.io/maven-central/v/com.github.shyiko.dotenv/dotenv.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.github.shyiko.dotenv%22%20AND%20a%3A%22dotenv%22)\n\nA [twelve-factor configuration](https://12factor.net/config) library for Java 8+.\n\nFeatures:\n- [seamless integration with Guice](https://github.com/shyiko/dotenv#integration-with-guice) (prefer Spring? see [here](https://github.com/shyiko/dotenv#integration-with-spring));\n- zero dependencies;\n- available in Maven Central.\n\n## Usage\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.shyiko.dotenv\u003c/groupId\u003e\n    \u003cartifactId\u003edotenv\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nENV resolution order (sources higher in the list take precedence over those located lower):\n- System.getenv() \n- `.env` file in current working directory (might not exist)\n- `.env` file on the classpath\n\n\u003e (java example)\n\nLet's assume you have a jar file (say `app.jar`) which contains .env file (e.g. `printf \"SCHEME=http\\nHOST=localhost\\n# comment\\nPORT=8080\" \u003e src/main/resources/.env`) and Main.java with the following `public static void main(...)`:   \n\n```java\nMap\u003cString, String\u003e dotEnv = DotEnv.load();\nSystem.out.println(dotEnv.get(\"SCHEME\") + \"://\" + dotEnv.get(\"HOST\") + \":\" + dotEnv.get(\"PORT\"))\n```\n\nExecuting the following\n\n```sh\nprintf \"HOST=0.0.0.0\" \u003e .env\nPORT=5050 app.jar\n```\n\nwill then output `http://0.0.0.0:5050`\n\n### Integration with [Guice](https://github.com/google/guice)\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.shyiko.dotenv\u003c/groupId\u003e\n    \u003cartifactId\u003edotenv-guice\u003c/artifactId\u003e\n    \u003cversion\u003e0.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n\u003e (Main.java)\n\n```java\nstatic class S {\n    private final String scheme;\n    private final String host;\n    private final int port;\n\n    @Inject\n    public S(\n        @DotEnvValue(\"SCHEME\") String scheme, \n        @DotEnvValue(\"HOST\") String host, \n        @DotEnvValue(\"PORT\") int port\n    ) {\n        this.scheme = scheme;\n        this.host = host;\n        this.port = port;\n    }\n\n    public void run() {\n        System.out.println(scheme + \"://\" + host + \":\" + port);\n    }\n}\n\npublic static void main(String[] args) {\n    Injector injector = Guice.createInjector(new DotEnvModule()/*, ... */);\n    S s = injector.getInstance(S.class);\n    s.run();\n}\n```\n\n### Integration with [Spring](https://spring.io/)\n\n\u003e (Main.java)\n\n```java\nstatic class S {\n    private final String scheme;\n    private final String host;\n    private final int port;\n\n    @Autowired\n    public S(\n        @Value(\"${SCHEME}\") String scheme, \n        @Value(\"${HOST}\") String host, \n        @Value(\"${PORT}\") int port\n    ) {\n        this.scheme = scheme;\n        this.host = host;\n        this.port = port;\n    }\n\n    public void run() {\n        System.out.println(scheme + \"://\" + host + \":\" + port);\n    }\n}\n\npublic static void main(String[] args) {\n    ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();\n    ctx.getEnvironment().getPropertySources().addFirst(\n        new MapPropertySource(\"dotenv\", new HashMap\u003c\u003e(DotEnv.load()))\n    );\n    ctx.refresh();\n    S s = ctx.getBeanFactory().createBean(S.class);\n    s.run();\n}\n```\n\n## Development\n\n```sh\ngit clone https://github.com/shyiko/dotenv \u0026\u0026 cd dotenv\n./mvnw # shows how to build, test, etc. project\n```\n\n## Legal\n\nAll code, unless specified otherwise, is licensed under the [MIT](https://opensource.org/licenses/MIT) license.  \nCopyright (c) 2017 Stanley Shyiko.\n","funding_links":[],"categories":["Projects","项目"],"sub_categories":["Configuration","配置"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshyiko%2Fdotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshyiko%2Fdotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshyiko%2Fdotenv/lists"}