4

I'm trying to upgrade our Spring version and use Spring IO Platform BOM to do so, but a few of our classes have gone missing (moved into other artifacts) or are no longer dependencies of some thing I was pulling in. I'm trying to find out which package they were originally part of (one example is CSVStrategy ). Some of these dependencies such as WhitespaceTokenizer have over a dozen artifact names that could be supplying it, and in order to find the correct upgrade path I need to figure out where it's currently coming from.

4

2 回答 2

1

一种可能的方法是获取资源(类)位置。如果该类来自 jar 文件,您至少会获得 jar 名称。从中您应该能够识别 Maven 工件。

someClass.getProtectionDomain().getCodeSource().getLocation().toURI();

或者使用 ResourceLoader 和记录器,您可以打印类路径/servlet 路径上所有类的列表。

@Autowired 
ResourceLoader resourceLoader;

public void printResourceLocations() {
    PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(resourceLoader);
    Resource[] resources = resolver.getResources("classpath*:com/**/*.class"));
    for (Resource resource : resources) {
        log.info(resource.getURI()); 
        // Not sure if that works, probably getFile() is ok?
    }
}    
于 2015-01-27T17:56:34.883 回答
0

我过去曾使用JBoss Tattletale来完成此类任务。我认为它不再被积极维护,但它仍然对我有用。这是我使用的配置。请注意,我必须将此添加到我的 POM 的构建部分,即使目标“报告”似乎暗示它是一个报告插件。

<plugin>
  <groupId>org.jboss.tattletale</groupId>
  <artifactId>tattletale-maven</artifactId>
  <!-- The version of the plugin you want to use -->
  <version>1.2.0.Beta2</version>
  <executions>
    <execution>
      <goals>
        <goal>report</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
  <!-- This is the location which will be scanned for generating tattletale reports -->
    <source>${project.build.directory}/${project.artifactId}/WEB-INF/lib</source>
    <!-- This is where the reports will be generated -->
    <destination>${project.build.directory}/site/tattletale</destination>
  </configuration>
</plugin>

您也可以尝试jHades。我还没有机会使用它,它在我的调查清单上。

于 2015-01-27T21:12:36.937 回答