3

Maven ビルド プロセス中に特定のインターフェイスのサブクラスのリストを作成し、実行時にそれを使用してそれらのクラスをロードする必要があります。webapp pomにreflections-maven(Googleコードリフレクションから)を追加しましたが、mavenビルド中には、Webアプリケーションのクラスのみが含まれ、web-inf/libそのアプリケーションのフォルダーにあるパッケージ化されたjar内のクラスは含まれません。以下は、私が使用した簡単な構成です。プラグインのソース コードを確認したところ、以下をスキャンしているようです: getProject().getBuild().getOutputDirectory().

プロジェクトの依存jarファイルをスキャンするようにプラグインを構成できる方法はありますか?

<plugin>
    <groupId>org.reflections</groupId>
    <artifactId>reflections-maven</artifactId>
    <version>0.9.9-RC1</version>
    <executions>
        <execution>
            <goals>
                <goal>reflections</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
</plugin>
4

1 に答える 1

7

たとえば、gmaven-plugin を使用して、好きな構成でリフレクションを簡単に実行できます。

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <dependencies>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.9-RC1</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <phase>generate-resources</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                    new org.reflections.Reflections("f.q.n")
                        .save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

したがって、おそらく特定のケースでは、適切な構成を使用するだけで済みます。

def urls = org.reflections.util.ClasspathHelper.forWebInfLib()
    new org.reflections.Reflections(urls)
        .save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
于 2013-12-25T12:03:02.760 に答える