0

I have an executable Jar file. This jar extracts a tar file and provides a Jar and an empty configuration file. My executable Jar populates the empty configuration file and calls the main method of extracted jar. The called main method looks for the configuration file in class path. Now the problem is the populated configuration file is not in the class path, instead its in some other directory.

How can I place it to class path and make sure it is loaded properly and accessible to the extracted jar?

Somnath Musib
  • 3,548
  • 3
  • 34
  • 47

1 Answers1

1

You have to add the directory where the file will eventually be placed to the JVMs classpath when starting it, i.e. using

java -jar -classpath <path-with-jars-and-your-directory> app.jar

Unless you run the extracted jar in a different JVM, you will have to give the right classpath when running the executable jar that does the extracting.

Another option is using a custom ClassLoader. You can create one that adds the right directory to its search path and use it as context classloader. More hints can be found in this answer.

Community
  • 1
  • 1
Pyranja
  • 3,529
  • 22
  • 24