web-dev-qa-db-ja.com

EclipseでMavenプロジェクトからJARファイルを作成する方法

私はMavenプロジェクトを持っていますが、Mavenに慣れていません。このMavenプロジェクトから実行可能JARファイルを作成して、Eclipseの別のプロジェクトで使用したかっただけです。どんな助けにも感謝します。

8
Questioner

JarをEclipseからビルドするには、mavenプロジェクト名を右クリックして、

実行> Mavenインストール

16
kswaughs

コマンドラインアプローチ:

プロジェクト(mavenプロジェクト)のルートでは、pom.xmlである必要があります。そのルートに移動してmvn packageを実行します。これが正しければ、プロジェクトのルートにtargetという名前の新しいフォルダーがあるはずです。このフォルダー内にはjarファイルが必要です。

3
Iker Aguayo

まず、Javaのセキュリティについて覚えておく必要があります。多くのjarファイルは、他のプロジェクト(たとえば、bouncycastle)に含まれている場合、fatjarでは機能しません。

Libが含まれていない単純な実行可能jarを実行していて、それらすべてをクラスパスで必要とする場合、デフォルトのビルド(パッケージ化タグがjarに設定されている場合)で問題なく、適切なマニフェストが必要です。

すべてのライブラリ(fatjar)が必要な場合は、自分で構成する必要があります。

そのためのプラグインがいくつかあります。たとえば、maven-shade-plugin

<plugin>
 <groupId>org.Apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>META-INF/*.SF</exclude>
                            <exclude>META-INF/*.RSA</exclude>
                            <exclude>META-INF/*.INF</exclude>
                        </excludes>
                    </filter>
                </filters>
                <transformers>
                    <transformer implementation="org.Apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Main-Class>my.package.MainClass</Main-Class>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </transformer>
                </transformers>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <shadedClassifierName>fat</shadedClassifierName>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
2
szefuf

Mavenのインストール- https://maven.Apache.org/download.cgi

Eclipse Run-> Maven installでプロジェクトに移動します

0
jyotinadda

Mavenプロジェクトを右クリックし、

Run As-> Maven Build ....を選択します

Goalsボックスにpackageと入力します。

「実行」をクリックします。

参照: https://teck4world.blogspot.com/2017/10/creating-jar-deployment-package-using.html

0
Dev4World