N2M
N2M

Reputation: 199

read jar file variables from a configuration file

I have a java program which uses an external jar file. The jar file has some variables(IP addresses) that needs to be read from a configuration file.

How to I create one such configuration file? How to do I read it in jar? [For now, I have hard-coded the needed variables data in the jar file. But I want to change it as and when I like, so changing in the configuration file is easier and I need not export(or re-compile) my jar file always]

To be more clear:

I have two java files: A.java, B.java. "A.java" is to be exported as a jar file and used by "B.java".

Now, I have to read some data(settings, IP addresses) within A.java. All these sort of data have to kept in a separate file and should be read into A.java. After enabling this, A.java will be exported as a jar file and used by B.java.

How could this be achieved?

Upvotes: 0

Views: 374

Answers (1)

Jayan
Jayan

Reputation: 18468

There are two different ways. If the jar is part of your classpath, then use Class.getResourceAsStream

It this is from plain jar some where, use JarFile

Upvotes: 1

Related Questions