java - 使用 javafx packager 的 JavaFX 中的类路径

标签 java maven javafx-2

我是 JavaFX 新手,我正在尝试使用 Maven 构建我的第一个应用程序。好吧,因为我不太喜欢将 ant 与 maven 混合,所以我有一个替代解决方案,使用 exec-maven-plugin 和 javafxpackager ,在这里找到:http://www.oracle.com/technetwork/articles/java/enterprisefxpt3-1735081.html

问题是,我不喜欢它在 jar 中解压所有依赖项的方式,所以我对它进行了“一点”修改,结果是:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <javafx.version>2.2</javafx.version>
    </properties>

    <build>
        <finalName>test</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.3</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/classes</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <executable>${java.home}/../bin/javafxpackager</executable>
                    <arguments>
                        <argument>-createjar</argument>
                        <argument>-appclass</argument>
                        <argument>test.HelloWorldApp</argument>
                        <argument>-srcdir</argument>
                        <argument>${project.build.directory}/classes</argument>
                        <argument>-outdir</argument>
                        <argument>${project.build.directory}/dist</argument>
                        <argument>-outfile</argument>
                        <argument>${project.name}.jar</argument>
                    </arguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>javafx</artifactId>
            <version>${javafx.version}</version>
            <scope>system</scope>
            <systemPath>${java.home}/lib/jfxrt.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <type>jar</type>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

嗯,我觉得真的很好看,超出预期!好吧,除了一个“小”问题之外:我在 Manifest.MF 上没有类路径条目,因此在运行时找不到添加的任何依赖项,而且我不知道如何添加它。有什么想法吗?

感谢大家的帮助!

编辑:也许这可以有所帮助,javafxpackager有一个参数classpath,我可以传递依赖项列表。所以我需要的是类路径,可能是一个字符串,只是将其添加到 javafxpackager 中。

最佳答案

如果你看 exec-maven-plugin POM configuration你看到你可以添加 <classpath/>标签。我还没试过,但应该可以。

<configuration>
    <executable>${java.home}/../bin/javafxpackager</executable>
    <arguments>
        <argument>-createjar</argument>
        <argument>-appclass</argument>
        <argument>test.HelloWorldApp</argument>
        <argument>-srcdir</argument>
        <argument>${project.build.directory}/classes</argument>
        <argument>-outdir</argument>
        <argument>${project.build.directory}/dist</argument>
        <argument>-outfile</argument>
        <argument>${project.name}.jar</argument>
        <argument>-classpath</argument>
        <!-- automatically creates the classpath using all project dependencies,
             also adding the project build directory -->
        <classpath/>
    </arguments>
</configuration>

关于java - 使用 javafx packager 的 JavaFX 中的类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13359626/

相关文章:

java - 将文本文件数据添加到 Arraylist

java - 如何(安全地)删除 Eclipse 中不必要的 Maven 依赖项?

java - 如何在本地部署 OpenShift Java EE 应用程序?

java - Bukkit Maven sk89q的命令框架

java - 表格单元格中的 TreeView Java FX 8

javafx-2 - 有没有办法在指定时间后隐藏一个阶段?

java - 如何强制复合索引出现在 Google Cloud 中?

java.io.UnsupportedEncodingException : unicode-1-1-utf-7?

java - 通用构造函数的好处

javafx-2 - JavaFX LineChart 悬停值