I have used launch4j to wrap an executable jar into an exe in my pom.xml (maven project file) file during compile/build time.
But is it possible to run launch4J from a piece of java code and creating an exe wrapper dynamically when the java application is executed, like:
import some.l4j.dependencies.*;
public class L4JTest {
public static void main(String[] args) {
Launch4JConfig l4jConfig = new Launch4JConfig ();
l4jConfig.setJarPath("path-to-jar-to-wrap");
l4jConfig.setOutfile("test.exe")
l4jConfig.setDontWrapJar(true);
...
l4jConfig.create();
}
}
Any pointers or links to examples are welcome!
Since you did not want to go thorough the Runtime.getRuntime().exec(..)
way, you will have to tinker around. We have used launch4J and we never had the use-case that you are looking for. I do not think launch4J has a documented Java API.
However, you may tinker with the Ant task used in launch4J and use it for your purpose here. Have a look at the task's source
You will see that it makes use of net.sf.launch4j.Builder
and net.sf.launch4j.config.Config
to "build" the EXE.