2

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!

u123
  • 15,603
  • 58
  • 186
  • 303
  • Did you consider using command line for launch4J and then calling it from a java program using ` Runtime.getRuntime().exec(....);` – ring bearer Sep 07 '11 at 19:13
  • Yeah that would be the "bruteforce" way, but maybe there is a java friendly API that could be included/used instead. – u123 Sep 07 '11 at 19:16

1 Answers1

3

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.

  • good luck!
ring bearer
  • 20,383
  • 7
  • 59
  • 72