3

Maven と launch4j を使用して、Java ベースのコマンド ライン アプリとそのすべての依存関係を単一の *.exe ファイルにラップしたいと考えています。

今、私はこれこれのようなSOに関するすべての同様の質問を読みましたが、うまくいきません。

誰でも単純な pom.xml スニペットを提供できますか?必要なすべての依存関係でこれを実現する方法。ところで、Eclipse の実行構成でどの Maven ビルド目標を実行する必要がありますか?

SOからコピーしたものは次のとおりです。

<!-- Launch4j -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
                <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.bluestemsoftware.open.maven.plugin</groupId>
            <artifactId>launch4j-plugin</artifactId>
            <version>1.5.0.0</version>
            <executions>

                <!-- Command-line exe -->
                <execution>
                    <id>l4j-cli</id>
                    <phase>package</phase>
                    <goals>
                        <goal>launch4j</goal>
                    </goals>
                    <configuration>
                        <headerType>console</headerType>
                        <outfile>target/importer.exe</outfile>
                        <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                        <errTitle>App Err</errTitle>
                        <classPath>
                            <mainClass>${mainClass}</mainClass>
                        </classPath>                
                        <jre>
                            <minVersion>1.5.0</minVersion>
                            <maxVersion>1.6.0</maxVersion>
                            <initialHeapSize>128</initialHeapSize>
                            <maxHeapSize>1024</maxHeapSize>
                        </jre>
                    </configuration>
                </execution>
            </executions>
        </plugin>  

Eclipse でlaunch4j:launch4jゴールを実行すると(これが正しい場合は?)、次のようになります。

プロジェクト インポーターでゴール org.bluestemsoftware.open.maven.plugin:launch4j-plugin:1.5.0.0:launch4j (default-cli) を実行できませんでした: ゴール org.bluestemsoftware.open.maven のパラメーター 'headerType'、'jre' .plugin:launch4j-plugin:1.5.0.0:launch4j が見つからないか無効です -> [ヘルプ 1]

たぶん、私は偽の目標を立ち上げているだけです...

4

1 に答える 1

0

ドライク!

あなたと非常によく似た構成で .exe ファイルを生成できました。私のポンポン全体に従います:

<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>test</groupId>
    <artifactId>test</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>test</name>

    <properties>
        <mainClass>foo.App</mainClass>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached> <!-- Make the shaded artifact not the main one -->
                    <shadedClassifierName>shaded</shadedClassifierName> <!-- set the suffix to the shaded jar -->
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <executions>
                    <!-- Command-line exe -->
                    <execution>
                        <id>l4j-cli</id>
                        <phase>package</phase>
                        <goals>
                            <goal>launch4j</goal>
                        </goals>
                        <configuration>
                            <headerType>console</headerType>
                            <outfile>target/importer.exe</outfile>
                            <jar>target/${artifactId}-${version}-shaded.jar</jar> <!-- 'shaded' is the value set on shadedClassifierName above -->
                            <classPath>
                                <mainClass>${mainClass}</mainClass>
                            </classPath>
                            <jre>
                                <minVersion>1.5.0</minVersion>
                                <initialHeapSize>128</initialHeapSize>
                                <maxHeapSize>1024</maxHeapSize>
                            </jre>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>LATEST</version>
        </dependency>
    </dependencies>

</project>

プラグインの groupId と artifactId を vorburger のものに変更しましたが、アラカイのバージョンも機能するはずです。次のことを確認してください。

  1. 正しい mainClass を構成しました
  2. 少なくとも 1 つの依存関係が宣言されている (過去にいくつかの「非常に小さい」アーティファクト/依存関係のないアーティファクトで問題が発生した)
  3. リポジトリからプラグインをダウンロードできます

シンプルな Maven アーキタイプでこの pom をテストしたところ、これがあなたのマシンで機能しない理由はわかりません。困ったことがあれば、ここで聞いてください。

.exe ファイルを生成するには、ターミナルで「mvn clean package」を実行するか、Eclipse でプロジェクトを右クリックし、「Run as...」>「Maven build...」と入力して「clean」と入力する必要があります。ゴールテキストフィールドのパッケージ」。

于 2012-05-21T19:34:51.553 に答える