Support Questions

Find answers, ask questions, and share your expertise

Dynamically generating xml files in jar?


I had written a program to extract data from phoenix and display it on a web page. Now i am trying to add the xml files(hbase-site,hdfs-site,core-site) dynamically into the jar by copying it from the server whenever i run it. Does anyone know how to do this?


New Contributor

Use a shell script to run a program that 1) generates the jar you want to launch HBase with, containing the versions of hbase-site, hdfs-site, and core-site that you want to use, 2) shutsdown the JVM, and 3) restarts the JVM using the jar just created.

Your question is more of a Java class loading question than an XML question. If you alter a Jar that is on the classpath while the JVM is running, the next time the JVM tries to load a resource from the jar , the JVM might crash or cause your app to go into an infinite loop. Furthermore, Windows will lock the jars your app is using at the OS level, so keep that in mind if you are trying to do this on Windows. It is possible to get around this by writing a custom class loader -- as is done in application servers such as Tomcat that allows for jar reloading -- but I'm guessing that is more than you want to do for this project.

Also, there are security concerns to your approach that you need to consider relating to the possibility the server delivering your config files has been spoofed.