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?

N2M
  • 199
  • 1
  • 15
  • Is the external JAR in the classpath of your "java program"? – acdcjunior May 23 '13 at 04:35
  • question is not clear....! "how to do I read in in jar" "jar has some variables", etc... – K Adithyan May 23 '13 at 04:40
  • A recent related question : http://stackoverflow.com/questions/16704631/can-you-store-data-inside-a-jar – Jayan May 23 '13 at 04:43
  • A faced a similar problem ... but I am trying to read from the code also present in the same jar... there... http://stackoverflow.com/questions/14209107/read-a-file-kept-in-a-jar-from-java-code-also-present-in-same-jar was helpful – AurA May 23 '13 at 04:45
  • @kAdithyan: question made more precise.. pls have a look. – N2M May 27 '13 at 08:40

1 Answers1

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

Jayan
  • 18,003
  • 15
  • 89
  • 143