use*_*901 1 jar class maven reflections
我需要在maven构建过程中为特定接口创建一个子类列表,然后在运行时使用它来加载这些类.我在我的webapp pom中添加了reflection-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>
Run Code Online (Sandbox Code Playgroud)
您可以使用任何您喜欢的配置轻松运行Reflections,例如使用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>
Run Code Online (Sandbox Code Playgroud)
因此,您需要做的就是使用正确的配置,可能在您的特定情况下:
def urls = org.reflections.util.ClasspathHelper.forWebInfLib()
new org.reflections.Reflections(urls)
.save("${project.build.outputDirectory}/META-INF/reflections/${project.artifactId}-reflections.xml")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2595 次 |
| 最近记录: |