1

私はJavaFXが初めてで、Mavenを使用して最初のアプリケーションを構築しようとしています。まあ、私は ant と maven を混在させるのはあまり好きではないので、 and を使用して別の解決策をexec-maven-plugin見つけjavafxpackagerました

問題は、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>

うーん、予想以上に格好良いと思います!まあ、1 つの「小さな」問題を除いてすべて: にクラスパス エントリManifest.MFがないため、追加された依存関係が実行時に見つからず、それを追加する方法がわかりません。何か案は?

助けてくれてありがとう!

編集:これが役立つかもしれません.javafxpackagerには、classpath依存関係のリストを渡すことができる引数があります。したがって、javafxpackagerに追加するためだけに、おそらく文字列としてのクラスパスが必要です。

4

2 に答える 2

0

exec-maven-pluginPOM 構成を見ると、<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>
于 2012-11-13T11:41:17.750 に答える