3

How to include additional files and folders (configuration files) when natively packaging Java applications?

When building the project, I have set the build file to create directories and copy additional files to the dist directory.

My normal builds (without native packaging) would result to this directory structure:

-> dist
   -> lib
   -> application.jar
   -> config folder //additional folder
   -> another additional folder //additional folder

Now, I would like to build my native installer (setup) having those addtional folders/files extracted together with my application and runtime.

Basically when my native installer is run, it will create these files:

-> app
   -> lib
   -> application.jar
   -> package.cfg
-> runtime
   -> jre
-> applcation.exe
-> application.ico
-> unins000.dat
-> unins000.exe

My additional files and folders are not included in my installer. I would like to have my installer with those additional files extracted, preferably like this

-> app
   -> lib
   -> config folder //additional folder
   -> another additional folder //additional folder
   -> application.jar
   -> package.cfg
-> runtime
   -> jre
-> applcation.exe
-> application.ico
-> unins000.dat
-> unins000.exe

By the way, I am using Ant Build tool and Inno for native packaging.

Warren Nocos
  • 1,222
  • 1
  • 14
  • 29
  • Have you found the solution for this? I'm also using the native packaging via ant build but my custom files are not being copied to the deployment directory. – Fappaz Feb 24 '17 at 00:48
  • Nevermind. OttPrime solution works, I just realised my script was copying the files to the wrong dir. – Fappaz Feb 24 '17 at 22:34
  • Can u show me complete code snippets? I am actually using NetBeans and can't find a proper method. @FernandoPaz – M. Ko Feb 27 '17 at 07:28
  • 1
    @M.Ko I'm not using NetBeans, just running an Ant script. Check out this snippet (probably the only relevant part for you is the target "do-deploy"): https://gist.github.com/anonymous/8398fd855637c60e8ee94d4b9f8437bb – Fappaz Feb 27 '17 at 21:02

1 Answers1

2

I've only ever built native packages with Wix, so I'm basing my answer on the knowledge I have from that experience. Add a target to your Ant build script and create an fx:deploy task. Set the nativeBundles attribute to exe. You can specify additional files and folders by adding fx:filesets to the fx:application/fx:resources XPATH. It might looking something like this.

<target name="deploy">
  <fx:deploy verbose="true" nativeBundles="exe" ...>
    <fx:application name="${app.title}" mainClass="${main.class}" version="${version}">
      <fx:resources>
        <fx:fileset dir="${base.dir}" includes="config/*.*" />
        <fx:fileset dir="${base.dir}" includes="data/*.*" />
      </fx:resources>
    </fx:application>
  </fx:deploy>
</target>

There is a lot more you can specify in the fx:resources section. There's more detailed information in the Oracle tutorials, particularly Section 6.

OttPrime
  • 1,878
  • 1
  • 15
  • 24
  • This was answered in 2015. Is this answer still valid and is it valid for JavaFX? – SedJ601 Oct 23 '18 at 16:27
  • @Sedrick It's been a couple of years since I worked in JavaFX, so I can't say for certain whether it's still a valid approach. I would expect that barring any major changes to Ant and its JavaFX tasks, this should still work but no promises. – OttPrime Nov 14 '18 at 14:43
  • I was asking because I could not get it to work. I found a workaround though. I package the files in the `jar`. Then when the program loads, it checks for the files in its folder. If it doesn't find the files, it extracts the files from the `jar` and added them to the folder. Thanks for your reply though. – SedJ601 Nov 14 '18 at 14:58