I have a jar file that has been turned into a .exe using L4J, and another jar file in appdata. The reason for having two files is that I need an updating mechanism.
My question:
How do I run the .exe file on the desktop, then load the jar in appdata from it?
You could use a
URLClassLoaderto load the second Jar at runtime.Depending on your needs, you may need a bridging interface (one that exists in both Jars) that you would call from your ‘exe’ to get the second Jar running…or you could simply use the second Jar’s
mainmethod 😉The other choice you have is to run another JVM.
UPDATE
In order to physical seperate the two elements of your application. You have a Jar wrapped in a EXE (aka launcher) and another Jar which is your application (aka application) (I assume).
So. Your launcher should have absolutely no idea about your application (little to no compile time dependencies).
Some how, we need to dynamically load the application from the launcher. To do that, we need a few things.
We need to be able to load the application into the launchers class loader context (so we can see it) and we some we to be able to load the application.
Dynamic ClassLoading
This can be achieved simply through the use of
URLClassLoaderApplication Loading
This can be achieved in one of two ways. You could simply use the
URLClassLoaderto find a launch the applicationsmainclass…Now, if your application Jar doesn’t have a
mainmethod, you can use the above example to launch just about any class you want…