#Dotenv Help

1 messages ยท Page 1 of 1 (latest)

sly holly
#

Hi. I'm new to Maven with Java. I'm trying to use a .env file I created inside of my package using io.github.cdimascio.dotenv.Dotenv. Could someone please give me a hand?

Error:

Could not find /.env on the classpath
blazing troutBOT
#

<@&987246399047479336> please have a look, thanks.

sly holly
brittle nebula
#

.env is for node?

blazing troutBOT
# brittle nebula .env is for node?

Looks like you attempted to use a command? Please note that we only use slash-commands on this server ๐Ÿ™‚

Try starting your message with a forward-slash / and Discord should open a popup showing you all available commands.
A command might then look like /foo ๐Ÿ‘

sly holly
#

Inside of my .env file, I have DISCORD_TOKEN=<token>

brittle nebula
#

that's for node though

sly holly
#

Oh

#

Oh wait a min... the tutorial I was watching is for Node... facepalm

#

So there's no such thing in Java, then?

naive oyster
sly holly
#

Title's misleading... It says "Java" ๐Ÿ˜‚

sly holly
blazing troutBOT
# sly holly .env

Looks like you attempted to use a command? Please note that we only use slash-commands on this server ๐Ÿ™‚

Try starting your message with a forward-slash / and Discord should open a popup showing you all available commands.
A command might then look like /foo ๐Ÿ‘

brittle nebula
#

you can use anything else for java like json, a config file or whatever

naive oyster
sly holly
#

Environment file to store things like bot tokens

naive oyster
#

yea

brittle nebula
#

nodejs has a .env package that you can store env vars in. on startup, it'll load the env vars

naive oyster
#

if you are using srping for example, you can use application.properties

#

but here

#

just create a file whereever you want

brittle nebula
#

the closest we have is Properties

naive oyster
#

and read it

sly holly
#

Is .txt valid?

naive oyster
#

I mean

#

you can use anything

#

but

brittle nebula
#

you can create a .properties file and store all your stuff in there discord_token=1234

#

and it'll have stuff like this

naive oyster
#

not sure thats what you want

sly holly
#

Yeah, that's cool

#

Just something to store my bot token

brittle nebula
#
    public static void main(String[] args) {
        Properties properties = new Properties();
        String propertiesFilePath = "path/to/your/config.properties";
        try {
            properties.load(new FileInputStream(propertiesFilePath));
            String value = properties.getProperty("discord_token");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
sly holly
#

Is Properties like part of the standard Java library?

brittle nebula
#

yes

sly holly
#

Awesome

naive oyster
#

@sly holly

sly holly
#

Oh?

brittle nebula
#

i don't wanna explain that to him

sly holly
#

Ok well Ig what I meant to ask was...

#

Do I have to install it as a dependecy in my pom.xml file?

brittle nebula
#

no

sly holly
#

Alr cool

#

One moment

brittle nebula
#

but basically, you should have a resources folder that you're supposed to bang that stuff in

#

but ala can explain if he wants

naive oyster
#

unless you want to use another format like json

#

when you generate a maven project

#

it will always have a resource folder

sly holly
#

So put .properties in resources?

#

I like doing best practice

naive oyster
#

so you can simply use

Properties properties = new Properties();
properties.load(MyClass.class.getResourceAsStream("/config.properties");
naive oyster
#

also, don't forget to gitignore it, so you don't commit your token by mistake

brittle nebula
#

you can also use something like detect-secrets to ensure that you don't commit it

sly holly
#

Ty for reminding me

naive oyster
#

and instead, you can add a config.properties.template that you will commit so anyone cloning your project can just copy paste this file and complete it

sly holly
#

Oh

#

That's actually smart

naive oyster
#

I stole this idea from tj bot

sly holly
#

Lol

#

Oh, I deleted my token on accident

#

Let me regen one sec

#

๐Ÿ˜‚

#

IOException e in Java is basically like saying store the error as e, right?

#

Ah ye

#

Ok good

#

Awesome, this language is very intuitive

#

YES! Thank you! Finally

#

That should not have taken me that long...

#

Man... Why do ppl market their videos with "Java" if it's JavaScript? facepalm

#

Tysm guys

brittle nebula
#

clickbait

sly holly
naive oyster
sly holly
#

If I print e, I'll get the error?

naive oyster
sly holly
#

Ooo

#

Cool

naive oyster
#

printing e directly only give minimal info

sly holly
#

I see

#

Java's so cool man

#

Why do ppl hate on this language? :(

brittle nebula
#

jealousy

#

and everyone hates on things better than them

naive oyster
sly holly
#

Arrow functions are interesting too, need to learn this

#

Not even sure what's going on here really

real moss
#

python folks are usually the ones to trash talk java because of it's verbosity(but mostly just stop at public static void main) ๐Ÿ‘€

sly holly
#

Nah, but I always found it interesting how articulate you could be with Java

#

I don't even get that in C++

real moss
#

yea i like that about java, no comments on c++ since havent used it. Those first few lines at the top of a c++ program scares me.

sly holly
#

C++, tbh, I don't really like the syntax in that language ๐Ÿคฃ

#

I just started with C++

naive oyster
sly holly
#

I never bothered learning lambda functions, ngl

#

So I'm still lost

#

Ah, Javacord API conveniently has lambdas under "Essential Knowledge"

naive oyster
sly holly
brittle nebula
#

Maybe consider JDA instead of javacord

#

I think most people are familiar with that

#

Javacord might be better but you're likely to get more help from us lot specifically because our server bot uses that, so you can reference it

naive oyster
#

@sly holly โ†‘

sly holly
sly holly
#

Talking about everyone using JDA, not Javacord

blazing troutBOT
#

@sly holly

Your question has been closed due to inactivity.

If it was not resolved yet, feel free to just post a message below
to reopen it, or create a new thread.

Note that usually the reason for nobody calling back is that your
question may have been not well asked and hence no one felt confident
enough answering.

When you reopen the thread, try to use your time to improve the quality
of the question by elaborating, providing details, context, all relevant code
snippets, any errors you are getting, concrete examples and perhaps also some
screenshots. Share your attempt, explain the expected results and compare
them to the current results.

Also try to make the information easily accessible by sharing code
or assignment descriptions directly on Discord, not behind a link or
PDF-file; provide some guidance for long code snippets and ensure
the code is well formatted and has syntax highlighting. Kindly read through
https://stackoverflow.com/help/how-to-ask for more.

With enough info, someone knows the answer for sure ๐Ÿ‘