2

mvn eclipse:eclipseコマンドを使用して my .projectandを生成してい.classpathます。

しかし、何らかの理由で、ファイルに 1 行追加したいと考えてい.classpathます。pom.xmlそれを達成するために使用できる設定はありますか?

<additionalConfig>の内容が消去されるため、 は使用できません.classpath

私はmaven 3.0.2とmaven-eclipse-plugin 2.8を使用しています。

4

1 に答える 1

4

それはその行が何であるかによって異なります。

  1. ソース フォルダーの場合は、 buildhelper-maven-pluginを 使用してライフサイクル フェーズの前に ソース フォルダーを追加しますgenerate-sources。これは、Eclipse プラグインによって自動的に取得されます。
  2. クラスパス コンテナーの場合は、classpathContainers パラメーターを使用できます。
  3. 出力フォルダーを (別のものからtarget/classes、またはtarget/test-classes別のものに) 変更する場合は、maven ビルド構成でそれらを変更します。

    <build>
        <!-- replace "target" -->
        <directory>somedir</directory>
        <!-- replace "target/classes" -->
        <outputDirectory>anotherdir</outputDirectory>
        <!-- replace "target/test-classes" -->
        <testOutputDirectory>yetanotherdir</testOutputDirectory>
    </build>
    

    これら 3 つのそれぞれを個別に構成でき、変更はEclipseプラグインによって取得されますが、outputDirectory(通常は を参照することによって) を挿入することをお勧めします。testOutputDirectorydirectory${project.build.directory}mvn clean${project.build.directory}

    <build>
        <directory>bin</directory>
        <outputDirectory>${project.build.directory}/main-classes
        </outputDirectory>
        <!-- this config will replace "target" with "bin",
             compile src/main/java to "bin/main-classes"
             and compile src/test/java to "bin/test-classes"
             (because the default config for <testOutputDirectory> is
             ${project.build.directory}/test-classes )
        -->
    </build>
    

参照:


更新:あなたの場合、唯一可能な解決策は、プログラムでファイルを編集することだと思い.classpathます。私がおそらく行うことは、次のようなものです。

  1. <profile>名前付きの日食(または何でも)を定義します
  2. gmaven プラグインの実行を定義します(このバージョンを使用してください)
  3. クラスパス コンテナーの .classpath ファイルをチェックし、欠落している場合は追加する短い groovy スクリプト (pom または外部でインライン) を作成します (実行をライフサイクル フェーズにバインドします。例: generate-resources)
  4. プロファイルのアクティベーションをに設定します<file><exists>${project.basedir}/.classpath</exists></file>(Eclipse プロジェクトでのみアクティブにしたいため)

このソリューションの問題点eclipse:eclipseは、フェーズではなく目標であるため、これを自動的に実行することはできないため、次のようにする必要があります。

mvn eclipse:eclipse    # two separate executions
mvn generate-resources # here, profile will be active

またはおそらくこれも機能します:

mvn -Peclipse eclipse:eclipse generate-resources
于 2011-02-10T16:10:29.163 に答える