2

Is it possible for a Jar to manipulate itself?

E.g. Changing the content of a text file inside of it.

I mean not by starting another executable or something like that.

Nick Russler
  • 4,608
  • 6
  • 51
  • 88
  • If found this [post](http://stackoverflow.com/a/8731582/441907) which may be a starting point. – Nick Russler Jan 09 '15 at 17:51
  • 3
    What is the *actual* problem that you're trying to solve. – kdgregory Jan 09 '15 at 17:56
  • @kdgregory Curiosity. I remembered that i could not do it with WinPe's and wondered if it may work for jar's. – Nick Russler Jan 09 '15 at 17:59
  • Does [this](http://stackoverflow.com/questions/728140/can-i-dynamically-unload-and-reload-other-versions-of-the-same-jar) coupled with cache-busting achieve what you want? – Ordous Jan 09 '15 at 18:05
  • The answer to this question may help: Do the JVMs file-locks (http://en.wikipedia.org/wiki/File_locking) the JAR when it is running? – Mindwin Remember Monica Jan 09 '15 at 18:05
  • @Mindwin No it does not. It may on a local filesystem, but if launching an application from a network drive you can disconnect and reconnect the drive through the app lifetime, as long as you don't request new classes while disconnected. – Ordous Jan 09 '15 at 18:07
  • @Ordous so basically the answer depends on the OS platform and machine topography. – Mindwin Remember Monica Jan 09 '15 at 18:09
  • @Mindwin Looks like it. It certainly locked all the library jars for me just now on local disk. So I guess the answer is "yes" if you can make the JVM drop the locks (by terminating the connection to a network location for example), and "I dunno, probably not" if you can't. – Ordous Jan 09 '15 at 18:18
  • @Ordous So the next question is: does the JVM crash if the network connection to the library folder is lost during runtime? And it will depend on the class loader NOT attempting to do something like loading a class/resource on the fly... – Mindwin Remember Monica Jan 09 '15 at 20:17
  • As written, your question can be answered with Yes, No, or Maybe. It all depends on what you're really trying to achieve. If you can narrow down to an *exact* situation, I'll answer (or, more likely, mark as a duplicate of the question that has the answer). But for now, I'm voting to close as Too Broad. – kdgregory Jan 10 '15 at 12:33
  • On the other hand, if you really are curious, you might find [this section](http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html) of the JVM Spec useful. Followed by a close reading of `URLClassLoader` and the classes it uses (especially `JarFile`). – kdgregory Jan 10 '15 at 12:39

0 Answers0