edvin / fxlauncher

Auto updating launcher for JavaFX Applications
Apache License 2.0
715 stars 107 forks source link

Unable to run Application #185

Open DatL4g opened 4 years ago

DatL4g commented 4 years ago

I run deployApp and I get a app.xml, fxlaucher.jar and App-1.0.jar When I try to run the fxlauncher.jar the console output is: cannot execute binary file: format error

I definitely made the file executable

And when I try to run generateNativeInstaller, there is a error while executing task: java.io.IOException: Cannot run program "javapackager": error=2, File not found But I have openjfx installed

My gradle looks like:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'no.tornado:fxlauncher-gradle-plugin:1.0.21'

        classpath 'javax.xml.bind:jaxb-api:2.3.1'
        classpath 'com.sun.xml.bind:jaxb-core:2.3.0.1'
        classpath 'com.sun.xml.bind:jaxb-impl:2.3.1'
    }
}

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.3.61'
    id 'org.openjfx.javafxplugin' version '0.0.7'
}

apply plugin: 'java'
apply plugin: 'no.tornado.fxlauncher'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

fxlauncher() {
    applicationVendor 'DatLag'
    applicationMainClass 'MainApplication'
    applicationUrl 'http://app.datlag.de'
    acceptDowngrade false
    deployTarget '/home/user/Projects/Kotlin/compiled'
}

javafx {
    modules = ['javafx.controls', 'javafx.media', 'javafx.graphics']
}

group 'de.datlag.app'
version '1.0'

repositories {
    mavenCentral()
    jcenter()
    google()
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    implementation 'no.tornado:tornadofx:1.7.19'

    implementation 'org.openjfx:javafx:11.0.2'
    implementation 'org.openjfx:javafx-base:11.0.2'
    implementation 'org.openjfx:javafx-controls:11.0.2'

    implementation 'com.jfoenix:jfoenix:9.0.8'

    implementation 'org.kordamp.ikonli:ikonli-core:11.3.4'
    implementation 'org.kordamp.ikonli:ikonli-javafx:11.3.4'
    implementation 'org.kordamp.ikonli:ikonli-material-pack:11.3.4'
    implementation 'org.kordamp.ikonli:ikonli-materialdesign-pack:11.3.4'
    implementation 'org.kordamp.ikonli:ikonli-fontawesome-pack:11.3.4'
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
edvin commented 4 years ago

I think there is some confusion going on here :) You can't execute a jar-file, you can run it with the java-command. However, some linux distros will employ a mechanism that makes it looks like you execute the jar file, but under the hood it's calling java -jar yourjarfile.jar.

To generate the native installers you must have javapackager installed, as the error message hints to. Java Packager is available with the JDK8 distribution from Oracle, probably not with OpenJDK.

DatL4g commented 4 years ago

Yeah I allready tried this but got an error: MainClass fxlauncher.Launcher not found java.lang.NoClassDefFoundError: javafx/application/Application

I'm not sure if this depends on my Application class, located in src/main/kotlin tried MainApplication and kotlin.MainApplication as applicationMainClass same result for both

mathis-m commented 3 years ago

Yeah I allready tried this but got an error: MainClass fxlauncher.Launcher not found java.lang.NoClassDefFoundError: javafx/application/Application

I'm not sure if this depends on my Application class, located in src/main/kotlin tried MainApplication and kotlin.MainApplication as applicationMainClass same result for both

@edvin @DATL4G was this resolved I am running into this too.

I have setup maven pipeline and installed all required tools. Mvn clean package runs successfully. But when trying to execute the fxlaunch.jar via Java command I get the same error. How can I resolve this? Setup: Java Env:

❯ java -version
openjdk version "15.0.2" 2021-01-19
OpenJDK Runtime Environment Corretto-15.0.2.7.1 (build 15.0.2+7)
OpenJDK 64-Bit Server VM Corretto-15.0.2.7.1 (build 15.0.2+7, mixed mode, sharing)

openjfx: javafx-sdk-16

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>mainModule</artifactId>
    <groupId>me.mathi</groupId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>mainModule</name>

    <properties>
        <kotlin.version>1.5.0-RC</kotlin.version>
        <javafx.version>15</javafx.version>
        <tornadofx.version>2.0.0-SNAPSHOT</tornadofx.version>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <kotlin.code.style>official</kotlin.code.style>
        <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>

        <!-- Installer Filename without suffix -->
        <app.filename>MyAppTest</app.filename>
        <!-- The JavaFX Application class name -->
        <app.mainClass>com.example.demo.app.MyApp</app.mainClass>
        <!-- Optional override to specify where the cached files are stored. Default is current working directory -->
        <app.cacheDir>USERLIB/MyAppTest</app.cacheDir>
        <!-- Optional parameters to the application, will be embedded in the launcher and can be overriden on the command line -->
        <app.parameters>--myOption=myValue --myOtherOption=myOtherValue</app.parameters>
        <!-- The Application vendor used by javapackager -->
        <app.vendor>Mathis Michel</app.vendor>
        <!-- The Application version used by javapackager -->
        <app.version>1.0</app.version>
        <!-- Base URL where you will host the application artifacts -->
        <app.url>http://localhost:8080</app.url>
        <!-- Optional scp target for application artifacts hosted at the above url -->
<!--        <app.deploy.target>w48839@fxldemo.tornado.no:fxldemo</app.deploy.target>-->
        <!-- The app and launcher will be assembled in this folder -->
        <app.dir>${project.build.directory}/app</app.dir>
        <!-- Native installers will be built in this folder -->
        <app.installerdir>${project.build.directory}/installer</app.installerdir>
        <!-- Should the client downgrade if the server version is older than the local version? -->
        <app.acceptDowngrade>false</app.acceptDowngrade>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <repositories>
        <repository>
            <id>snapshots-repo</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>
        <plugins>
            <!-- Compile project jar to appdir -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <outputDirectory>${app.dir}</outputDirectory>
                </configuration>
            </plugin>
            <!-- Copy dependencies to appdir -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <excludeScope>provided</excludeScope>
                    <outputDirectory>${app.dir}</outputDirectory>
                    <stripVersion>true</stripVersion>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${kotlin.version}</version>
                <executions>
                    <execution>
                        <id>compile</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                        <configuration>
                            <jvmTarget>1.8</jvmTarget>
                        </configuration>
                    </execution>
                    <execution>
                        <id>test-compile</id>
                        <phase>test-compile</phase>
                        <goals>
                            <goal>test-compile</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <jvmTarget>1.8</jvmTarget>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <!-- Generate app.xml manifest -->
                <executions>
                    <execution>
                        <id>create-manifest</id>
                        <phase>package</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>fxlauncher.CreateManifest</mainClass>
                            <arguments>
                                <argument>${app.url}</argument>
                                <argument>${app.mainClass}</argument>
                                <argument>${app.dir}</argument>
                                <argument>--cache-dir=${app.cacheDir}</argument>
                                <argument>--accept-downgrade=${app.acceptDowngrade}</argument>
                                <argument>--include-extensions=jpg</argument>
                                <argument>${app.parameters}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Embed app.xml inside fxlauncher.xml so we don't need to reference app.xml to start the app -->
                    <execution>
                        <id>embed-manifest-in-launcher</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>jar</executable>
                            <workingDirectory>${app.dir}</workingDirectory>
                            <arguments>
                                <argument>uf</argument>
                                <argument>fxlauncher.jar</argument>
                                <argument>app.xml</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <!-- Use jpackage to make installer -->
                    <execution>
                        <id>installer</id>
                        <phase>install</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>jpackage</executable>

                            <arguments>
                                <argument>--name</argument>
                                <argument>${app.filename}</argument>

                                <argument>--input</argument>
                                <argument>${app.dir}</argument>

                                <argument>--main-jar</argument>
                                <argument>fxlauncher.jar</argument>

                                <argument>--main-class</argument>
                                <argument>fxlauncher.Launcher</argument>

                                <argument>--dest</argument>
                                <argument>${app.installerdir}</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>no.tornado</groupId>
            <artifactId>tornadofx</artifactId>
            <version>${tornadofx.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test-junit</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>

        <dependency>
            <groupId>no.tornado</groupId>
            <artifactId>fxlauncher</artifactId>
            <version>1.0.21</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx</artifactId>
            <version>${javafx.version}</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.1</version>
            <scope>runtime</scope>
        </dependency>

    </dependencies>

</project>
vs4dhak commented 1 year ago

@edvin , @DATL4G, @mathis-m got the same error -> "Class fxlauncher/Launcher not found."

This happens when you startup the application after installation.

If I run the fxlauncher.jar via the terminal with the command below, everything runs successfully.

Looks like its some issue with how the generated exe looks for the fxlauncher.jar?

java -jar fxlauncher.jar