#.config file for Java application?

1 messages · Page 1 of 1 (latest)

mystic sonnetBOT
#

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

jovial lark
#

Basically something like config.json or something which lets you set parameters which are then used in my program

lone ibex
#

yeah, just load the file on startup

jovial lark
#

How do I do that

#

And how will Java know, what param to paste into my vars

lone ibex
#

you would load the file, for example using Gson for json files. then you would decide which variables the data should be assigned to

#

you could also map it to a class

#

for example, you could map your Vars class to a json file. look into Gson

jovial lark
#

ok i see, do you have a link to a documentation or something

lone ibex
#

you could even just use a text file, then read the plain text file

#
List<String> lines = Files.readAllLines(...);

// parse the lines```
#

you could use a Properties file

#

many different options

jovial lark
#

Ok nice. Thanks, do you know by any chance, if there is a way in Java, to start a SSH listener port which will on connection from the client prompt for username and password?

frigid blade
#

Java has a built-in class for this called Properties

jovial lark
#

omg ok so thats actually OP

#

and easy

#

lol

lone ibex
#

keep in mind, Properties is pretty simplistic, key/value pairs

jovial lark
#

yes

#

I see xd

lone ibex
#

if you ever need nested data, you'll have to change formats

#

otherwise, Properties would be the easiest

jovial lark
#

yes

jovial lark
lone ibex
jovial lark
#

How do I do dat

lone ibex
#

oh my bad, thought you said ssl. you could use JSch

jovial lark
#

Ah ye I seen that

#

Ok so I was going the right way

#

Is JSch secure

lone ibex
#

its as secure as SSH2, since its just an implementation of it

jovial lark
#

kk good

#

Do I need that or can I juse parse the properties into my vars file?

lone ibex
#

thats just the class definition

#

you'd use a Properties object to read the file

jovial lark
#

kk good

lone ibex
#

look at examples online if needed

jovial lark
#

I was just confused bc I wondered why anyone would reuse the constructor and attributes of a class just for properties xD

jovial lark
#

well, "extends" just inherites the attributes and methods, so I was confused by that line as it inherits an empty class basically to "Hashtable"

jovial lark
#

oh

lone ibex
#

extending from Hashtable just says "a Properties object is a Hashtable", allowing Properties to inherit from Hashtable

#

extending creates an "is-a" relationship between 2 types

jovial lark
#

ohhh ye, in school we are just using it to like inherit attributes and classes yk