Could not find ./.env on the file system (working directory:/)
Hi readers
I am setting up this package in my java project, have added dependency and also created a .env file but when calling configure() as mentioned below
Dotenv dotenv = Dotenv .configure() .load();
I followed your document but i want to use .env file from the root of the project for example : exampleproject/app/.env
and getting this error every time i do
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Caused by: io.github.cdimascio.dotenv.DotenvException: Could not find /.env on the classpath at io.github.cdimascio.dotenv.internal.ClasspathHelper.loadFileFromClasspath(ClasspathHelper.java:25) at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:55) at io.github.cdimascio.dotenv.internal.DotenvParser.lines(DotenvParser.java:87) at io.github.cdimascio.dotenv.internal.DotenvParser.parse(DotenvParser.java:60) at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:76) at com.example.activity.splash.onCreate(Splash.java:33) at android.app.Activity.performCreate(Activity.java:8591) at android.app.Activity.performCreate(Activity.java:8570) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1384) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4150) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4325) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2574) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.app.ActivityThread.main(ActivityThread.java:8757) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067) Suppressed: io.github.cdimascio.dotenv.DotenvException: Could not find ./.env on the file system (working directory: /) at io.github.cdimascio.dotenv.internal.DotenvReader.read(DotenvReader.java:60)
I ended up pasting .env file on every root of the project for example project/app/ , project/ , project/app/src ... but nun of that worked. !
I'm using GraalVM native-image on pc.
Ok, because
mvn -pl server spring-boot:run does not remove the server from the user.dir path
and
mvn -pl server -Pnative native:compile removing the server from the path. So I have to add it to the path
String projectPath = System.getProperty("user.dir", ".");
if (!projectPath.contains("server")) {
projectPath = projectPath + "\\server\\";
}
System.out.println("Current resource path: " + projectPath);
Dotenv dotenv = Dotenv.configure().directory(projectPath).load();
I put the .env under the server
root-folder
| __ client
| __ server/
| __ resource/
| __ .env (not in here)
.env (here)
pom.xml
Have a look at the android usage section here https://github.com/cdimascio/dotenv-kotlin?tab=readme-ov-file#android-usage
Note the use of env not .env
Have a look at the android usage section here https://github.com/cdimascio/dotenv-kotlin?tab=readme-ov-file#android-usage
Note the use of env not .env
I make a mistake. I thought this was on PC but it's mobile. But still, I'm trying to get it working with spring-boot and graalvm
two different types and it just doesn't work well together.
mvn -pl server spring-boot:run
and
mvn -pl server -Pnative native:compile