代码之家  ›  专栏  ›  技术社区  ›  Leder

我想用maven3为kotlin/tornadofx项目打包JAR

  •  0
  • Leder  · 技术社区  · 7 年前

    创建JAR时JDK 11和JavaFX依赖项出错。Fat JAR正在构建,但执行不起作用,请参阅下面的错误。。。

    这是我的清单.MF:


    Manifest-Version: 1.0
    Created-By: Apache Maven 3.5.4
    Built-By: gerri
    Build-Jdk: 11.0.1
    Class-Path: javax.json-api-1.1.2 tornadofx-1.7.17 kotlin-reflect-1.2.60 
     kotlin-stdlib-1.3.0-rc-198 kotlin-stdlib-common-1.3.0-rc-198 kotlin-std
     lib-jdk7-1.2.60 kotlin-stdlib-jdk8-1.2.60 javax.json-1.1.2 annotations-
     13.0
    Main-Class: de.auticon.maven.tornadofx.MainAppKt
    

    更新 pom.xml 按要求:


    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>de.auticon.maven.tornadofx</groupId>
        <artifactId>de-auticon-maven-tornadofx</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>de.auticon.maven.tornadofx de-auticon-maven-tornadofx</name>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <kotlin.version>1.3.0-rc-198</kotlin.version>
            <kotlin.code.style>official</kotlin.code.style>
            <junit.version>4.12</junit.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-stdlib</artifactId>
                <version>${kotlin.version}</version>
            </dependency>
            <dependency>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-test-junit</artifactId>
                <version>${kotlin.version}</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>no.tornado</groupId>
                <artifactId>tornadofx</artifactId>
                <version>1.7.17</version>
            </dependency>
    
            <dependency>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-controls</artifactId>
                <version>11-ea+19</version>
            </dependency>
    
        </dependencies>
    
        <build>
            <sourceDirectory>src/main/kotlin</sourceDirectory>
            <testSourceDirectory>src/test/kotlin</testSourceDirectory>
    
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <archive>
                            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                        </archive>
                    </configuration>
    
                </plugin>
                <plugin>
                    <groupId>org.jetbrains.kotlin</groupId>
                    <artifactId>kotlin-maven-plugin</artifactId>
                    <version>${kotlin.version}</version>
                    <configuration>
                        <jvmTarget>1.8</jvmTarget>
                    </configuration>
                    <executions>
                        <execution>
                            <id>compile</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>compile</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>test-compile</id>
                            <phase>test-compile</phase>
                            <goals>
                                <goal>test-compile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4.1</version>
                    <configuration>
                        <!-- get all project dependencies -->
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <!-- MainClass in mainfest make a executable jar -->
                        <archive>
                          <manifest>
                            <mainClass>de.auticon.maven.tornadofx.MainAppKt</mainClass>
                          </manifest>
                        </archive>
    
                    </configuration>
                    <executions>
                      <execution>
                        <id>make-assembly</id>
                                            <!-- bind to the packaging phase -->
                        <phase>package</phase> 
                        <goals>
                            <goal>single</goal>
                        </goals>
                      </execution>
                    </executions>
                </plugin>
    
    
            </plugins>
        </build>
    
    </project>
    

    javafxpackager 如前所述 here?

    D:\Source\deauticonmaventornadofx\target>java -jar de-auticon-maven-tornadofx-1.0-SNAPSHOT-jar-with-dependencies.jar
    Error: JavaFX runtime components are missing, and are required to run this application
    
    0 回复  |  直到 7 年前