1

I'm facing a problem currently with JavaFX. I would like to create an exe or an installer for my application. I used Netbeans and Eclipse, but none works.
I've been searching on the web and there are many great advice to make it work.
But nobody talks about external files. Here is my project :

-data
  --db.sqlite
-src
  --css
  --html
  --com.stackoverflow.....
-lib

And here is a part of my build.xml file I use in NetBeans :

<?xml version="1.0" encoding="UTF-8"?>
<project name="GTBad2.0" default="default" basedir="." xmlns:fx="javafx:com.sun.javafx.tools.ant">
    <description>My application.</description>
    <import file="nbproject/build-impl.xml"/>    
    <target name="-post-jfx-deploy">
         <taskdef resource="com/sun/javafx/tools/ant/antlib.xml"
         uri="javafx:com.sun.javafx.tools.ant"
         classpath=".:path/to/sdk/lib/ant-javafx.jar"/>
         <fx:deploy verbose="true" width="${javafx.run.width}" height="${javafx.run.height}" 
         nativeBundles="all"
         outdir="${basedir}/${dist.dir}" outfile="${application.title}">
             <fx:application name="${application.title}" mainClass="${javafx.main.class}"/>
             <fx:resources>
                 <fx:fileset dir="${basedir}/${dist.dir}" includes="*.jar"/>
                 <fx:fileset dir="${basedir}/${dist.dir}" includes="lib/*.jar"/>
             </fx:resources>
             <fx:info title="MyApp" vendor="me"/>
         </fx:deploy>          
    </target>
 </project>


The libs are correctly imported in my build.xml. But how to make sure to include css, html and data directories ? My database seems to be loaded only if I use absolute paths in the code instead of using
DriverManager.getConnection("jdbc:sqlite:data/db.sqlite");

Thanks for helping me.

EDIT :

Thanks for your replies. But I'm not asking if it is possible or not to create an exe. It is. JavaFX (e(fx)eclipse for example) provides tools to create an exe from a build.xml. I can assure you that it works because it worked for me for simple javafx projects. What I'm asking is how to link the database file and resources file to my exe.

Hope my asking is understandable.

Dunnbar
  • 53
  • 1
  • 8
  • 1
    you can't export java application as .exe , you can export it as jar file as following thread : http://stackoverflow.com/questions/11172003/exporting-jar-file-in-eclipse-using-javafx – Radi Aug 06 '15 at 11:43
  • If you just want to create an installer (exe), you can use a tool like NSIS http://nsis.sourceforge.net/ This will however not create a runnable exe from your JavaFX application but just an installer moving your files into place – Jan Gassen Aug 06 '15 at 11:58
  • you also might want to look at this thread http://stackoverflow.com/questions/516399/how-do-i-create-an-exe-for-a-java-program – Jan Gassen Aug 06 '15 at 11:59
  • 1
    Have a look at the [JavaFX deployment tutorial](http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm). In particular, ["Self-contained application packaging"](http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm#BCGIBBCI) shows how to package an application as a native package. – James_D Aug 06 '15 at 13:13
  • Is your build.xml file to big to post in its entirety? Usually these are only ~100 lines. – James_D Aug 06 '15 at 14:40
  • 1
    It's hard to tell because you haven't posted the correct information, but I don't think this has anything to do with creating a "self-contained package" (i.e. an exe file). You need the data to be in the jar file you create (which is then bundled up into the exe with all sorts of other stuff, like the JVM). Can you run from the jar file? I would make sure you get basic jar packaging working the way you want first, *then* try to package as an exe. – James_D Aug 06 '15 at 15:43
  • I created the jar file, and it works fine. No error at all. The exe, doesn't want to run and stops at the moment I ask to connect to the database. – Dunnbar Aug 06 '15 at 17:20
  • Does the exe can be blocked by the firewall ? That would maybe explain why the jar perfectly works, where as the exe doesn't. – Dunnbar Aug 06 '15 at 17:54

1 Answers1

0

That generated EXE-file is just a unified way to load the JVM, which is setup to your configuration. As for the static files: they are easy to get via SomeClass.getClassLoader().getResource(path), but you have to distinct read-only and writable files, because you can't directly edit that database inside that JAR-file.

When using javafx-maven-plugin (and using maven instead of ant), you could create a native bundle where your database lies beside your JavaFX-jar-file.

Example configuration:

<plugin>
    <groupId>com.zenjava</groupId>
    <artifactId>javafx-maven-plugin</artifactId>
    <version>8.2.0</version>
    <configuration>
        <vendor>YourCompany</vendor>
        <mainClass>specify.your.mainclass</mainClass>
        <additionalAppResources>src/resources/folderWithYourDatabaseFile</additionalAppResources>
    </configuration>
</plugin>

Disclaimer: I'm the maintainer of the javafx-maven-plugin.

FibreFoX
  • 2,858
  • 1
  • 19
  • 41