2

Javaビルドプロセスでmavenを使用しています。以下は、すべての依存関係を持つ単一の jar を作成するコードのスニペットです。ビルドへの小さな変更でのデータ転送を減らすために、すべてのプロジェクト ファイル (依存関係を含む) をフォルダー target/build に配置したいと思います。アプリを実行しているリモート マシンとフォルダーを再同期し、次のコマンドでアプリを実行する予定です。

java -cp target/build/* <classname>

これを実現するためにこのスニペットを変更するにはどうすればよいですか? ここのドキュメントを読みましたが、修正をつなぎ合わせる方法がわかりません:

4

2 に答える 2

3

ビルド時に依存関係をターゲット フォルダーにコピーするように maven を取得する方法を尋ねていますか?

Maven依存関係プラグインが必要だと思います。プロジェクトの依存関係を指定した出力フォルダーにコピーします。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${targetDirectory}</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

jarプラグインをmavenして、jarをパッケージ化する場所を指定する必要があるようです。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <outputDirectory>${dir}</outputDirectory>
            </configuration>
        </plugin>
于 2012-09-16T19:12:18.893 に答える
1

Maven依存関係プラグインを使用する

それはゴールを持っています: copy-dependencies. これはあなたが望むことをするはずです。

例(ドキュメントから取得)

  <project>
    [...]
    <build>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>2.5.1</version>
          <executions>
            <execution>
              <id>copy-dependencies</id>
              <phase>package</phase>
              <goals>
                <goal>copy-dependencies</goal>
              </goals>
              <configuration>
                <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
  </build>
   [...]
</project>
于 2012-09-16T19:12:36.843 に答える