0

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?

5
  • Is the external JAR in the classpath of your "java program"? Commented May 23, 2013 at 4:35
  • question is not clear....! "how to do I read in in jar" "jar has some variables", etc... Commented May 23, 2013 at 4:40
  • A recent related question : stackoverflow.com/questions/16704631/… Commented May 23, 2013 at 4:43
  • A faced a similar problem ... but I am trying to read from the code also present in the same jar... there... stackoverflow.com/questions/14209107/… was helpful Commented May 23, 2013 at 4:45
  • @kAdithyan: question made more precise.. pls have a look. Commented May 27, 2013 at 8:40

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.