Forum Stats

  • 3,854,538 Users
  • 2,264,379 Discussions
  • 7,905,721 Comments

Discussions

JavaFX deploying

3400862
3400862 Member Posts: 2
edited Apr 17, 2017 4:56AM in JavaFX 2.0 and Later

Hi, I'd like to deploy my JavaFX application not using just one huge jar file.

I'd like to distribute it using my small jar file and then the lib folder with all the other dependencies.

I use netbeans and maven. How can I do it?

Thank.

eudriscabrera-JavaNetjsmith

Answers

  • eudriscabrera-JavaNet
    eudriscabrera-JavaNet Member Posts: 214 Bronze Badge
    edited Feb 18, 2017 6:22PM

    You can distribute the application by following these steps:

    1. Create a zip file that contains the application JAR file (MyApp.jar) and the accompanying lib folder that contains the dependencies (ie, others jar files)
    2. Send the file to the people who will use the application. Instruct them to unpack the zip file, making sure that the MyApp.jar file and the lib folder are in the same folder.

    The users of your application should be able to run it by double-clicking the JAR file. If this does not work for them, show them the information in the Troubleshooting JAR File Associations section.

    More information is available at https://netbeans.org/kb/articles/javase-deploy.html

  • bouye-JavaNet
    bouye-JavaNet Member Posts: 394 Silver Badge
    edited Feb 19, 2017 6:01PM

    Hum what you describe is just the standard way for NetBean packaging in non-Maven projects.

  • eudriscabrera-JavaNet
    eudriscabrera-JavaNet Member Posts: 214 Bronze Badge
    edited Feb 19, 2017 11:33PM

    bouye-JavaNet!.

    For maven projects you can use the Assembly Plugin to create a custom build distribution.

    You can customize your build to create a zip file that contains the application JAR file (MyApp.jar) and the accompanying lib folder that contains the dependencies (ie, others jar files).

    The assembly plugin has several formats (zip, tar, tar. gz (or tgz),tar.bz2 (or tbz2), jar, dir, war) and you can use it as you need it.

    Here's a demo project that demonstrates the usage of the Apache Maven Assembly Plugin to create a build distribution.

    https://github.com/ecabrerar/maven-examples/tree/master/maven-deployment

  • 3400862
    3400862 Member Posts: 2
    edited Feb 22, 2017 9:52AM

    Hi,

    thanks for the anwser.

    Anyway, what you are saying is working with normale maven application. I can use the "maven-dependency-plugin" to copy all the dependencies into the lib folder. Everything is ok this way.

    But, if the application is a JavaFX application, it doesn't work. Unless I tell the maven-dependency-plugin to unpack the dependencies wich at te end produces just un big jar. If I don't do that, the jar created cannot find dependencies, even if they are copied under lib folder.

    eudriscabrera-JavaNet
  • jsmith
    jsmith Member Posts: 2,856
    edited Feb 22, 2017 1:46PM

    As you are using maven and JavaFX, you should probably be using the JavaFX Maven plugin:

    https://github.com/javafx-maven-plugin/javafx-maven-plugin

    eudriscabrera-JavaNet
  • eudriscabrera-JavaNet
    eudriscabrera-JavaNet Member Posts: 214 Bronze Badge
    edited Feb 22, 2017 11:16PM

    If you created your JavaFX Maven Project with Netbeans, it has created the pom.xml with the default configuration to build and deploy the application. You need to comment the plugins lines added by default and add the JavaFX Maven Plugin.

    <plugin>    <groupId>com.zenjava</groupId>    <artifactId>javafx-maven-plugin</artifactId>    <version>8.6.0</version>    <configuration>        <mainClass>your.package.with.Launcher</mainClass>    </configuration></plugin>

    You have to specify the main class.

    To create your executable file, call mvn jfx:jar. The jar-file will be placed at target/jfx/app.

    Also, you can customize the maven phase to generate the jar file using another maven command (phase, IE: package, install, etc.)

    Here's a demo project that demonstrates the usage of the JavaFX Maven Plugin to create a build distribution.

    https://github.com/ecabrerar/maven-examples/tree/master/javafx-maven-deployment

    I'm using the package phase to generate the jar file.

    Best Regards.

    jsmith
  • omers
    omers Member Posts: 13
    edited Apr 17, 2017 4:56AM

    I had the same problem. This plugin has solved the problem. My usage is as follows;

                <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-assembly-plugin</artifactId>                <executions>                    <execution>                        <phase>prepare-package</phase>                        <goals>                            <goal>single</goal>                        </goals>                        <configuration>                            <archive>                                <manifest>                                    <mainClass>Main</mainClass>                                </manifest>                            </archive>                            <descriptorRefs>                                <descriptorRef>jar-with-dependencies</descriptorRef>                            </descriptorRefs>                        </configuration>                    </execution>                </executions>            </plugin>
This discussion has been closed.