Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch4J - how to attach dependent jars to generated exe

Tags:

java

jar

launch4j

I have a simple java project, which requires external jars. I build this with netbeans and after Clean and Build command, I can find in dist directory the following structure:

-myApp.jar
-lib/
     library1.jar
     library2.jar

typical, I would say.

Now, I'd like to distribute myApp.jar with dependent libraries as one exe. Is this possible? I am trying to use Launch4J. In the GUI I create the config file, there are some options in cp section

<cp>lib/swing-layout-1.0.4.jar</cp>

but it seems to be classpath, and it is the only place I can refer to my extra jars.

After exe file is created, I can't find dependend libs in the exe (exe can be opened with winrar) and thus my application crashes.

How can I make the exe file properly then?

Thanks for your help.

like image 676
norbi771 Avatar asked Nov 11 '13 23:11

norbi771


2 Answers

When you are converting your .jar file

  1. Go to classpath tab
  2. Check custom classpath
  3. On main class select your .jar from your dist folder after building the project
  4. On the classpath textarea add your libraries, you add them right below that textarea writting the full path to the lib (of course including the lib, ie "C:\folder\lib\file.jar")

Example

like image 169
SaFteiNZz Avatar answered Oct 08 '22 11:10

SaFteiNZz


I also faced the same issue while migrating my .jar to exe. I also had many dependent libraries as well. So These were the steps I performed :

  1. Download and Install launch4j.

  2. Open your project in netbeans. Clean and build the project.

  3. Make sure you have a folder named 'dist' in the project directory. It will have your jar files with lib folder(containing the dependent libraries).
  4. Open launch 4j.
  5. Create output file in the dist folder. For example : OutputFile : D:******\My_App\dist\my_application.exe
  6. Browse your jar file in the next row. For example : Jar : D:******\My_App\dist\my_application.jar
  7. Go to classpath tab. Tick CustomClasspath. Press browse icon, and browse to your jar file which is located in the dist folder.
  8. Specify Min Jre version in the JRE tab.
  9. Save the configration.
  10. Build the wrapper(by clicking the settings icon)
  11. Your exe file will be generated in the dist folder. Thats it :)
like image 26
Salman Saleh Avatar answered Oct 08 '22 11:10

Salman Saleh