Giter VIP home page Giter VIP logo

Comments (8)

jessevdp avatar jessevdp commented on May 24, 2024 1

Ahh I see. That's totally fixed. I included the resources folder under src/main instead of in the root of the project.

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

@jessevdp, this is the correct behavior. The two paths are different locations.
The first, ./ is a relative path, thus Dotenv will search with respect to the current working directory
The second, / is an absolute path, thus Dotenv will search the root of your filesystem for .env

Note if there are no matches, Dotenv will then search the java classpath. It's common that this be the resources directory particularly if you're using the maven project structure

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

@jessevdp this stuff gets a bit tricky, but ultimately, you need to know the directory from which java is executed from. It determines the point from which relative paths are resolved e.g. ./

You're IDE may also set this directory. If possible, it may be worth executing your app from the command line to be absolutely sure which directory you are running from

Let me know if i can help in anyway, I definitely want to get this working for you

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

These examples may help

Spring: .env is pulled from the classpath. It is stored in resources directory:
https://github.com/cdimascio/kotlin-swagger-spring-functional-template/tree/master/src/main/resources

There is an Android example in the README as well, if needed

from dotenv-kotlin.

jessevdp avatar jessevdp commented on May 24, 2024

I am using maven. I did just try to make a resource directory and put the .env file in there and I removed all the configuration. This still gave me the same error.

I am using Eclipse so there's a slight chance that just adding the folder didn't have the desired effect. I know there's a .classpath file. I'm just not very used to what it does or how to use it. By default it's excluded from source control as well.

I come from the world of Node.js where everyone has to compile and execute their apps from the command line. These concepts are kind of foreign to me.


https://github.com/cdimascio/kotlin-swagger-spring-functional-template/tree/master/src/main/resources`

That link is broken, should remove the back-tick.

The first, ./ is a relative path, thus Dotenv will search with respect to the current working directory
The second, / is an absolute path, thus Dotenv will search the root of your filesystem for .env.

Oeps, that's true. Guess it was in too having a bit of tunnel vision yesterday 😂

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

@jessevdp here is a super basic example of a Maven project using dotenv where .env lives in the the resources directory

https://github.com/cdimascio/java-dotenv-example

Be sure to set up the directory structure as shown in this example. It aligns with the standard Maven structure.

The example has instructions to run on the command line. Once, you see that work, try from eclipse

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

Here is a direct link to the actual code (you'll find it is very simple):

https://github.com/cdimascio/java-dotenv-example/blob/master/src/main/java/io/github/cdimascio/examples/dotenv/Main.java

And a link to the .env file
https://github.com/cdimascio/java-dotenv-example/blob/master/src/main/resources/.env

And the pom.xml file
https://github.com/cdimascio/java-dotenv-example/blob/master/pom.xml

Again, the project is set up using the Maven structure. Assuming you set your project up similarly (which is recommended even if not using java-dotenv), it should work

from dotenv-kotlin.

cdimascio avatar cdimascio commented on May 24, 2024

Excellent! I added the example to the README. closing this out

from dotenv-kotlin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.