【问题标题】:Is it possible to use reflections-maven to scan for classes inside jars in web-Inf/lib?是否可以使用反射-maven 扫描 web-Inf/lib 中 jar 内的类?
【发布时间】:2013-11-06 13:15:30
【问题描述】:

我需要在 Maven 构建过程中为特定接口创建一个子类列表,然后在运行时使用它来加载这些类。我在我的 webapp pom 中添加了反射-maven(来自谷歌代码反射),但在 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>

【问题讨论】:

    标签: class maven jar reflections


    【解决方案1】:

    您可以使用您喜欢的任何配置轻松运行反射,例如使用 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")
    

    【讨论】:

      猜你喜欢
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 2013-06-22
      • 1970-01-01
      • 2012-01-11
      相关资源
      最近更新 更多